Chromium Code Reviews| 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 "mandoline/ui/aura/surface_binding.h" | 5 #include "mandoline/ui/aura/surface_binding.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 namespace mandoline { | 28 namespace mandoline { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // OutputSurface --------------------------------------------------------------- | 31 // OutputSurface --------------------------------------------------------------- |
| 32 | 32 |
| 33 // OutputSurface implementation for a view. Pushes the surface id to View when | 33 // OutputSurface implementation for a view. Pushes the surface id to View when |
| 34 // appropriate. | 34 // appropriate. |
| 35 class OutputSurfaceImpl : public cc::OutputSurface { | 35 class OutputSurfaceImpl : public cc::OutputSurface { |
| 36 public: | 36 public: |
| 37 OutputSurfaceImpl(mojo::View* view, | 37 OutputSurfaceImpl(mojo::View* view, |
| 38 const scoped_refptr<cc::ContextProvider>& context_provider, | 38 const scoped_refptr<cc::ContextProvider>& context_provider); |
| 39 mojo::Surface* surface, | |
| 40 uint32_t id_namespace, | |
| 41 uint32_t* next_local_id); | |
| 42 ~OutputSurfaceImpl() override; | 39 ~OutputSurfaceImpl() override; |
| 43 | 40 |
| 44 // cc::OutputSurface: | 41 // cc::OutputSurface: |
| 45 void SwapBuffers(cc::CompositorFrame* frame) override; | 42 void SwapBuffers(cc::CompositorFrame* frame) override; |
| 46 | 43 |
| 47 private: | 44 private: |
| 48 mojo::View* view_; | 45 mojo::View* view_; |
| 49 mojo::Surface* surface_; | 46 mojo::CompositorFrameReceiverPtr receiver_; |
| 50 uint32_t id_namespace_; | |
| 51 uint32_t* next_local_id_; // Owned by PerViewManagerState. | |
| 52 uint32_t local_id_; | |
| 53 gfx::Size surface_size_; | 47 gfx::Size surface_size_; |
| 54 | 48 |
| 55 DISALLOW_COPY_AND_ASSIGN(OutputSurfaceImpl); | 49 DISALLOW_COPY_AND_ASSIGN(OutputSurfaceImpl); |
| 56 }; | 50 }; |
| 57 | 51 |
| 58 OutputSurfaceImpl::OutputSurfaceImpl( | 52 OutputSurfaceImpl::OutputSurfaceImpl( |
| 59 mojo::View* view, | 53 mojo::View* view, |
| 60 const scoped_refptr<cc::ContextProvider>& context_provider, | 54 const scoped_refptr<cc::ContextProvider>& context_provider) |
| 61 mojo::Surface* surface, | |
| 62 uint32_t id_namespace, | |
| 63 uint32_t* next_local_id) | |
| 64 : cc::OutputSurface(context_provider), | 55 : cc::OutputSurface(context_provider), |
| 65 view_(view), | 56 view_(view) { |
| 66 surface_(surface), | |
| 67 id_namespace_(id_namespace), | |
| 68 next_local_id_(next_local_id), | |
| 69 local_id_(0u) { | |
| 70 capabilities_.delegated_rendering = true; | 57 capabilities_.delegated_rendering = true; |
| 71 capabilities_.max_frames_pending = 1; | 58 capabilities_.max_frames_pending = 1; |
| 59 view->RequestCompositorFrameReceiver(GetProxy(&receiver_)); | |
| 72 } | 60 } |
| 73 | 61 |
| 74 OutputSurfaceImpl::~OutputSurfaceImpl() { | 62 OutputSurfaceImpl::~OutputSurfaceImpl() { |
| 75 } | 63 } |
| 76 | 64 |
| 77 void OutputSurfaceImpl::SwapBuffers(cc::CompositorFrame* frame) { | 65 void OutputSurfaceImpl::SwapBuffers(cc::CompositorFrame* frame) { |
| 78 gfx::Size frame_size = | 66 receiver_->SubmitCompositorFrame(mojo::CompositorFrame::From(*frame), |
| 79 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 67 mojo::Closure()); |
|
rjkroege
2015/08/19 23:45:44
are you correctly interlocking?
Fady Samuel
2015/08/20 16:22:44
I'm not sure what you mean here. We submit frames
| |
| 80 if (frame_size != surface_size_) { | |
| 81 if (local_id_ != 0u) | |
| 82 surface_->DestroySurface(local_id_); | |
| 83 local_id_ = (*next_local_id_)++; | |
| 84 surface_->CreateSurface(local_id_); | |
| 85 auto qualified_id = mojo::SurfaceId::New(); | |
| 86 qualified_id->local = local_id_; | |
| 87 qualified_id->id_namespace = id_namespace_; | |
| 88 view_->SetSurfaceId(qualified_id.Pass()); | |
| 89 surface_size_ = frame_size; | |
| 90 } | |
| 91 | |
| 92 surface_->SubmitFrame(local_id_, | |
| 93 mojo::CompositorFrame::From(*frame), | |
| 94 mojo::Closure()); | |
| 95 | 68 |
| 96 client_->DidSwapBuffers(); | 69 client_->DidSwapBuffers(); |
| 97 client_->DidSwapBuffersComplete(); | 70 client_->DidSwapBuffersComplete(); |
| 98 } | 71 } |
| 99 | 72 |
| 100 } // namespace | 73 } // namespace |
| 101 | 74 |
| 102 // PerViewManagerState --------------------------------------------------------- | 75 // PerViewManagerState --------------------------------------------------------- |
| 103 | 76 |
| 104 // State needed per ViewManager. Provides the real implementation of | 77 // State needed per ViewManager. Provides the real implementation of |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } | 143 } |
| 171 | 144 |
| 172 scoped_ptr<cc::OutputSurface> | 145 scoped_ptr<cc::OutputSurface> |
| 173 SurfaceBinding::PerViewManagerState::CreateOutputSurface(mojo::View* view) { | 146 SurfaceBinding::PerViewManagerState::CreateOutputSurface(mojo::View* view) { |
| 174 // TODO(sky): figure out lifetime here. Do I need to worry about the return | 147 // TODO(sky): figure out lifetime here. Do I need to worry about the return |
| 175 // value outliving this? | 148 // value outliving this? |
| 176 mojo::CommandBufferPtr cb; | 149 mojo::CommandBufferPtr cb; |
| 177 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); | 150 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); |
| 178 scoped_refptr<cc::ContextProvider> context_provider( | 151 scoped_refptr<cc::ContextProvider> context_provider( |
| 179 new mojo::ContextProviderMojo(cb.PassInterface().PassHandle())); | 152 new mojo::ContextProviderMojo(cb.PassInterface().PassHandle())); |
| 180 return make_scoped_ptr(new OutputSurfaceImpl( | 153 return make_scoped_ptr(new OutputSurfaceImpl(view, context_provider)); |
| 181 view, context_provider, surface_.get(), id_namespace_, &next_local_id_)); | |
| 182 } | 154 } |
| 183 | 155 |
| 184 SurfaceBinding::PerViewManagerState::PerViewManagerState( | 156 SurfaceBinding::PerViewManagerState::PerViewManagerState( |
| 185 mojo::Shell* shell, | 157 mojo::Shell* shell, |
| 186 mojo::ViewManager* view_manager) | 158 mojo::ViewManager* view_manager) |
| 187 : shell_(shell), | 159 : shell_(shell), |
| 188 view_manager_(view_manager), | 160 view_manager_(view_manager), |
| 189 returner_binding_(this), | 161 returner_binding_(this), |
| 190 id_namespace_(0u), | 162 id_namespace_(0u), |
| 191 next_local_id_(0u) { | 163 next_local_id_(0u) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 } | 224 } |
| 253 | 225 |
| 254 SurfaceBinding::~SurfaceBinding() { | 226 SurfaceBinding::~SurfaceBinding() { |
| 255 } | 227 } |
| 256 | 228 |
| 257 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { | 229 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { |
| 258 return state_->CreateOutputSurface(view_); | 230 return state_->CreateOutputSurface(view_); |
| 259 } | 231 } |
| 260 | 232 |
| 261 } // namespace mandoline | 233 } // namespace mandoline |
| OLD | NEW |