| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { | 50 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { |
| 51 bool update_source_texture = !reflector_texture_ || reflector_changed_; | 51 bool update_source_texture = !reflector_texture_ || reflector_changed_; |
| 52 reflector_changed_ = false; | 52 reflector_changed_ = false; |
| 53 if (!reflector_texture_) { | 53 if (!reflector_texture_) { |
| 54 reflector_texture_.reset(new ReflectorTexture(context_provider())); | 54 reflector_texture_.reset(new ReflectorTexture(context_provider())); |
| 55 | 55 |
| 56 GLES2Interface* gl = context_provider_->ContextGL(); | 56 GLES2Interface* gl = context_provider_->ContextGL(); |
| 57 | 57 |
| 58 const int max_texture_size = | 58 const int max_texture_size = |
| 59 context_provider_->ContextCapabilities().max_texture_size; | 59 context_provider_->ContextCapabilities().max_texture_size; |
| 60 int texture_width = std::min(max_texture_size, surface_size_.width()); | 60 int texture_width = std::min(max_texture_size, reshape_size_.width()); |
| 61 int texture_height = std::min(max_texture_size, surface_size_.height()); | 61 int texture_height = std::min(max_texture_size, reshape_size_.height()); |
| 62 | 62 |
| 63 gl->BindTexture(GL_TEXTURE_2D, reflector_texture_->texture_id()); | 63 gl->BindTexture(GL_TEXTURE_2D, reflector_texture_->texture_id()); |
| 64 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 64 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 65 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 65 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 66 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 66 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 67 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 67 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 68 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(kFboTextureFormat), | 68 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(kFboTextureFormat), |
| 69 texture_width, texture_height, 0, | 69 texture_width, texture_height, 0, |
| 70 GLDataFormat(kFboTextureFormat), | 70 GLDataFormat(kFboTextureFormat), |
| 71 GLDataType(kFboTextureFormat), nullptr); | 71 GLDataType(kFboTextureFormat), nullptr); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 100 gl->DeleteFramebuffers(1, &fbo_); | 100 gl->DeleteFramebuffers(1, &fbo_); |
| 101 fbo_ = 0; | 101 fbo_ = 0; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 void OffscreenBrowserCompositorOutputSurface::Reshape( | 105 void OffscreenBrowserCompositorOutputSurface::Reshape( |
| 106 const gfx::Size& size, | 106 const gfx::Size& size, |
| 107 float scale_factor, | 107 float scale_factor, |
| 108 const gfx::ColorSpace& color_space, | 108 const gfx::ColorSpace& color_space, |
| 109 bool alpha) { | 109 bool alpha) { |
| 110 if (size == surface_size_) | 110 reshape_size_ = size; |
| 111 return; | |
| 112 | |
| 113 surface_size_ = size; | |
| 114 device_scale_factor_ = scale_factor; | |
| 115 DiscardBackbuffer(); | 111 DiscardBackbuffer(); |
| 116 EnsureBackbuffer(); | 112 EnsureBackbuffer(); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() { | 115 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() { |
| 120 bool need_to_bind = !!reflector_texture_.get(); | 116 bool need_to_bind = !!reflector_texture_.get(); |
| 121 | 117 |
| 122 EnsureBackbuffer(); | 118 EnsureBackbuffer(); |
| 123 DCHECK(reflector_texture_.get()); | 119 DCHECK(reflector_texture_.get()); |
| 124 DCHECK(fbo_); | 120 DCHECK(fbo_); |
| 125 | 121 |
| 126 if (need_to_bind) { | 122 if (need_to_bind) { |
| 127 GLES2Interface* gl = context_provider_->ContextGL(); | 123 GLES2Interface* gl = context_provider_->ContextGL(); |
| 128 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 124 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 129 } | 125 } |
| 130 } | 126 } |
| 131 | 127 |
| 132 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( | 128 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( |
| 133 cc::OutputSurfaceFrame frame) { | 129 cc::OutputSurfaceFrame frame) { |
| 134 gfx::Size surface_size = frame.size; | 130 gfx::Size surface_size = frame.size; |
| 135 DCHECK(surface_size == surface_size_); | 131 DCHECK(surface_size == reshape_size_); |
| 136 gfx::Rect swap_rect = frame.sub_buffer_rect; | 132 gfx::Rect swap_rect = frame.sub_buffer_rect; |
| 137 | 133 |
| 138 if (reflector_) { | 134 if (reflector_) { |
| 139 if (swap_rect == gfx::Rect(surface_size)) | 135 if (swap_rect == gfx::Rect(surface_size)) |
| 140 reflector_->OnSourceSwapBuffers(surface_size); | 136 reflector_->OnSourceSwapBuffers(surface_size); |
| 141 else | 137 else |
| 142 reflector_->OnSourcePostSubBuffer(swap_rect, surface_size); | 138 reflector_->OnSourcePostSubBuffer(swap_rect, surface_size); |
| 143 } | 139 } |
| 144 | 140 |
| 145 // TODO(oshima): sync with the reflector's SwapBuffersComplete | 141 // TODO(oshima): sync with the reflector's SwapBuffersComplete |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 reflector_changed_ = true; | 178 reflector_changed_ = true; |
| 183 EnsureBackbuffer(); | 179 EnsureBackbuffer(); |
| 184 } | 180 } |
| 185 } | 181 } |
| 186 | 182 |
| 187 void OffscreenBrowserCompositorOutputSurface::OnSwapBuffersComplete() { | 183 void OffscreenBrowserCompositorOutputSurface::OnSwapBuffersComplete() { |
| 188 client_->DidSwapBuffersComplete(); | 184 client_->DidSwapBuffersComplete(); |
| 189 } | 185 } |
| 190 | 186 |
| 191 } // namespace content | 187 } // namespace content |
| OLD | NEW |