OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/renderer_host/offscreen_canvas_compositor_frame_sink.h
" |
| 6 |
| 7 #include "cc/surfaces/surface.h" |
| 8 #include "cc/surfaces/surface_manager.h" |
| 9 #include "content/browser/compositor/surface_utils.h" |
| 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( |
| 15 const cc::SurfaceId& surface_id, |
| 16 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 17 : surface_id_(surface_id), client_(std::move(client)) {} |
| 18 |
| 19 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { |
| 20 if (surface_factory_) { |
| 21 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 22 if (!manager) { |
| 23 // Inform SurfaceFactory that SurfaceManager's no longer alive to |
| 24 // avoid its destruction error. |
| 25 surface_factory_->DidDestroySurfaceManager(); |
| 26 } else { |
| 27 manager->InvalidateSurfaceClientId(surface_id_.client_id()); |
| 28 } |
| 29 surface_factory_->Destroy(surface_id_); |
| 30 } |
| 31 } |
| 32 |
| 33 // static |
| 34 void OffscreenCanvasCompositorFrameSink::Create( |
| 35 const cc::SurfaceId& surface_id, |
| 36 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 37 cc::mojom::MojoCompositorFrameSinkRequest request) { |
| 38 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( |
| 39 surface_id, std::move(client)), |
| 40 std::move(request)); |
| 41 } |
| 42 |
| 43 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( |
| 44 cc::CompositorFrame frame, |
| 45 const SubmitCompositorFrameCallback& callback) { |
| 46 if (!surface_factory_) { |
| 47 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 48 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); |
| 49 surface_factory_->Create(surface_id_); |
| 50 |
| 51 manager->RegisterSurfaceClientId(surface_id_.client_id()); |
| 52 } |
| 53 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 54 callback); |
| 55 } |
| 56 |
| 57 void OffscreenCanvasCompositorFrameSink::SetNeedsBeginFrame( |
| 58 bool needs_begin_frame) { |
| 59 NOTIMPLEMENTED(); |
| 60 } |
| 61 |
| 62 void OffscreenCanvasCompositorFrameSink::ReturnResources( |
| 63 const cc::ReturnedResourceArray& resources) { |
| 64 client_->ReturnResources(resources); |
| 65 } |
| 66 |
| 67 void OffscreenCanvasCompositorFrameSink::WillDrawSurface( |
| 68 const cc::SurfaceId& id, |
| 69 const gfx::Rect& damage_rect) {} |
| 70 |
| 71 void OffscreenCanvasCompositorFrameSink::SetBeginFrameSource( |
| 72 cc::BeginFrameSource* begin_frame_source) {} |
| 73 |
| 74 } // namespace content |
OLD | NEW |