Chromium Code Reviews| 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_surface_service_impl.h" | |
| 6 | |
| 7 #include "base/bind_helpers.h" | |
| 8 #include "cc/surfaces/surface.h" | |
| 9 #include "cc/surfaces/surface_manager.h" | |
| 10 #include "content/browser/compositor/surface_utils.h" | |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 | |
| 15 template <> | |
| 16 struct TypeConverter<cc::SurfaceId, blink::mojom::SurfaceIdPtr> { | |
| 17 static cc::SurfaceId Convert(const blink::mojom::SurfaceIdPtr& input) { | |
|
Fady Samuel
2016/06/02 22:32:23
Please avoid using type converters.
| |
| 18 return input ? | |
| 19 cc::SurfaceId(input->id_namespace, input->local_id, input->nonce) : | |
| 20 cc::SurfaceId(); | |
| 21 } | |
| 22 }; | |
| 23 | |
| 24 template <> | |
| 25 struct TypeConverter<blink::mojom::SurfaceIdPtr, cc::SurfaceId> { | |
| 26 static blink::mojom::SurfaceIdPtr Convert(const cc::SurfaceId& input) { | |
| 27 blink::mojom::SurfaceIdPtr result = blink::mojom::SurfaceId::New(); | |
| 28 result->id_namespace = input.id_namespace(); | |
| 29 result->local_id = input.local_id(); | |
| 30 result->nonce = input.nonce(); | |
| 31 return result; | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 template <> | |
| 36 struct TypeConverter<cc::SurfaceSequence, blink::mojom::SurfaceSequencePtr> { | |
| 37 static cc::SurfaceSequence Convert( | |
| 38 const blink::mojom::SurfaceSequencePtr& input) { | |
| 39 return input ? cc::SurfaceSequence(input->id_namespace, input->sequence) | |
| 40 : cc::SurfaceSequence(); | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 template <> | |
| 45 struct TypeConverter<blink::mojom::SurfaceSequencePtr, cc::SurfaceSequence> { | |
| 46 static blink::mojom::SurfaceSequencePtr Convert( | |
| 47 const cc::SurfaceSequence& input) { | |
| 48 blink::mojom::SurfaceSequencePtr result = | |
| 49 blink::mojom::SurfaceSequence::New(); | |
| 50 result->id_namespace = input.id_namespace; | |
| 51 result->sequence = input.sequence; | |
| 52 return result; | |
| 53 } | |
| 54 }; | |
| 55 | |
| 56 } // namespace mojo | |
| 57 | |
| 58 namespace content { | |
| 59 | |
| 60 // static | |
| 61 void OffscreenCanvasSurfaceServiceImpl::Create( | |
| 62 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> request) | |
| 63 { | |
| 64 // |binding_| will take ownership of OffscreenCanvasSurfaceServiceImpl | |
| 65 new OffscreenCanvasSurfaceServiceImpl(std::move(request)); | |
| 66 } | |
| 67 | |
| 68 OffscreenCanvasSurfaceServiceImpl::OffscreenCanvasSurfaceServiceImpl( | |
| 69 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> request) | |
| 70 : binding_(this, std::move(request)) | |
| 71 { | |
| 72 id_allocator_ = CreateSurfaceIdAllocator(); | |
| 73 } | |
| 74 | |
| 75 OffscreenCanvasSurfaceServiceImpl::~OffscreenCanvasSurfaceServiceImpl() | |
| 76 { | |
| 77 if (surface_factory_) { | |
| 78 surface_factory_->DestroyAll(); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void OffscreenCanvasSurfaceServiceImpl::GetSurfaceId( | |
| 83 const GetSurfaceIdCallback& callback) { | |
| 84 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 85 | |
| 86 cc::SurfaceId surface_id = id_allocator_->GenerateId(); | |
| 87 | |
| 88 blink::mojom::SurfaceIdPtr surface_id_ptr = | |
| 89 mojo::ConvertTo<blink::mojom::SurfaceIdPtr>(surface_id); | |
| 90 callback.Run(std::move(surface_id_ptr)); | |
|
Fady Samuel
2016/06/02 22:32:23
This shouldn't need to be sync.
| |
| 91 } | |
| 92 | |
| 93 void OffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation( | |
| 94 const blink::mojom::SurfaceIdPtr surface_id) | |
| 95 { | |
| 96 cc::SurfaceManager* manager = GetSurfaceManager(); | |
| 97 if (!surface_factory_) { | |
| 98 surface_factory_ = base::WrapUnique( | |
| 99 new cc::SurfaceFactory(manager, this)); | |
| 100 } | |
| 101 surface_factory_->Create(mojo::ConvertTo<cc::SurfaceId>(surface_id)); | |
| 102 } | |
| 103 | |
| 104 void OffscreenCanvasSurfaceServiceImpl::Require( | |
| 105 blink::mojom::SurfaceIdPtr surface_id, | |
| 106 blink::mojom::SurfaceSequencePtr sequence) | |
| 107 { | |
| 108 cc::SurfaceManager* manager = GetSurfaceManager(); | |
| 109 cc::Surface* surface = manager->GetSurfaceForId( | |
| 110 mojo::ConvertTo<cc::SurfaceId>(surface_id)); | |
| 111 if (!surface) { | |
| 112 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | |
| 113 return; | |
| 114 } | |
| 115 surface->AddDestructionDependency( | |
| 116 mojo::ConvertTo<cc::SurfaceSequence>(sequence)); | |
| 117 } | |
| 118 | |
| 119 void OffscreenCanvasSurfaceServiceImpl::Satisfy( | |
| 120 blink::mojom::SurfaceSequencePtr sequence) | |
| 121 { | |
| 122 cc::SurfaceSequence ccSequence = | |
| 123 mojo::ConvertTo<cc::SurfaceSequence>(sequence); | |
| 124 std::vector<uint32_t> sequences; | |
| 125 sequences.push_back(ccSequence.sequence); | |
| 126 cc::SurfaceManager* manager = GetSurfaceManager(); | |
| 127 manager->DidSatisfySequences(ccSequence.id_namespace, &sequences); | |
| 128 } | |
| 129 | |
| 130 // TODO: Implement cc::SurfaceFactoryClient functions for resources return. | |
| 131 void OffscreenCanvasSurfaceServiceImpl::ReturnResources( | |
| 132 const cc::ReturnedResourceArray& resources) | |
| 133 { | |
| 134 } | |
| 135 | |
| 136 void OffscreenCanvasSurfaceServiceImpl::WillDrawSurface( | |
| 137 cc::SurfaceId id, const gfx::Rect& damage_rect) | |
| 138 { | |
| 139 } | |
| 140 | |
| 141 void OffscreenCanvasSurfaceServiceImpl::SetBeginFrameSource( | |
| 142 cc::BeginFrameSource* begin_frame_source) | |
| 143 { | |
| 144 } | |
| 145 | |
| 146 } // namespace content | |
| OLD | NEW |