OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/compositor/offscreen_browser_compositor_output_surface .h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "cc/output/compositor_frame.h" | |
9 #include "cc/output/compositor_frame_ack.h" | |
10 #include "cc/output/gl_frame_data.h" | |
11 #include "cc/output/output_surface_client.h" | |
12 #include "cc/resources/resource_provider.h" | |
13 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor.h" | |
14 #include "content/browser/compositor/reflector_impl.h" | |
15 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
16 #include "content/public/browser/browser_thread.h" | |
17 #include "gpu/command_buffer/client/context_support.h" | |
18 #include "gpu/command_buffer/client/gles2_interface.h" | |
19 #include "third_party/khronos/GLES2/gl2.h" | |
20 #include "third_party/khronos/GLES2/gl2ext.h" | |
21 | |
22 using cc::CompositorFrame; | |
23 using cc::GLFrameData; | |
24 using cc::ResourceProvider; | |
25 using gpu::gles2::GLES2Interface; | |
26 | |
27 namespace content { | |
28 | |
29 OffscreenBrowserCompositorOutputSurface:: | |
30 OffscreenBrowserCompositorOutputSurface( | |
31 const scoped_refptr<ContextProviderCommandBuffer>& context, | |
32 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, | |
33 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | |
34 overlay_candidate_validator) | |
35 : BrowserCompositorOutputSurface(context, | |
36 vsync_manager, | |
37 overlay_candidate_validator.Pass()), | |
38 fbo_(0), | |
39 is_backbuffer_discarded_(false), | |
40 backing_texture_id_(0), | |
41 weak_ptr_factory_(this) { | |
42 capabilities_.max_frames_pending = 1; | |
43 capabilities_.uses_default_gl_framebuffer = false; | |
44 } | |
45 | |
46 OffscreenBrowserCompositorOutputSurface:: | |
47 ~OffscreenBrowserCompositorOutputSurface() { | |
48 DiscardBackbuffer(); | |
49 } | |
50 | |
51 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { | |
52 is_backbuffer_discarded_ = false; | |
53 | |
54 if (!backing_texture_id_) { | |
55 GLES2Interface* gl = context_provider_->ContextGL(); | |
56 cc::ResourceFormat format = cc::RGBA_8888; | |
57 | |
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); | |
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); | |
63 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
64 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), | |
65 surface_size_.width(), surface_size_.height(), 0, | |
66 GLDataFormat(format), GLDataType(format), nullptr); | |
piman
2015/04/28 18:38:13
note: since you never use this one as a texture, o
oshima
2015/04/28 20:39:01
Yes, I'm going to use this texture directly on the
| |
67 } | |
68 } | |
69 | |
70 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() { | |
71 is_backbuffer_discarded_ = true; | |
72 | |
73 GLES2Interface* gl = context_provider_->ContextGL(); | |
74 | |
75 if (backing_texture_id_) { | |
76 gl->DeleteTextures(1, &backing_texture_id_); | |
77 backing_texture_id_ = 0; | |
78 } | |
79 | |
80 if (fbo_) { | |
81 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
82 gl->DeleteFramebuffers(1, &fbo_); | |
83 fbo_ = 0; | |
84 } | |
85 } | |
86 | |
87 void OffscreenBrowserCompositorOutputSurface::Reshape(const gfx::Size& size, | |
88 float scale_factor) { | |
89 if (size == surface_size_) | |
90 return; | |
91 | |
92 surface_size_ = size; | |
93 device_scale_factor_ = scale_factor; | |
94 DiscardBackbuffer(); | |
95 EnsureBackbuffer(); | |
96 } | |
97 | |
98 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() { | |
99 EnsureBackbuffer(); | |
100 DCHECK(backing_texture_id_); | |
101 | |
102 GLES2Interface* gl = context_provider_->ContextGL(); | |
103 | |
104 if (!fbo_) | |
105 gl->GenFramebuffers(1, &fbo_); | |
106 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | |
107 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | |
108 backing_texture_id_, 0); | |
109 } | |
110 | |
111 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( | |
112 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_) { | |
117 if (frame->gl_frame_data->sub_buffer_rect == | |
118 gfx::Rect(frame->gl_frame_data->size)) | |
119 reflector_->OnSourceSwapBuffers(); | |
120 else | |
121 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | |
122 } | |
123 | |
124 client_->DidSwapBuffers(); | |
125 | |
126 // TODO(oshima): sync with the reflector's SwapBuffersComplete. | |
127 uint32_t sync_point = | |
128 context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); | |
129 context_provider_->ContextSupport()->SignalSyncPoint( | |
130 sync_point, base::Bind(&OutputSurface::OnSwapBuffersComplete, | |
131 weak_ptr_factory_.GetWeakPtr())); | |
132 } | |
133 | |
134 } // namespace content | |
OLD | NEW |