| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/native_viewport/viewport_surface.h" | 5 #include "mojo/services/native_viewport/viewport_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "cc/surfaces/surface_id_allocator.h" | 8 #include "cc/surfaces/surface_id_allocator.h" |
| 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 10 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" | 10 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
| 11 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h" |
| 11 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 12 | 13 |
| 13 namespace mojo { | 14 namespace mojo { |
| 14 | 15 |
| 15 ViewportSurface::ViewportSurface(SurfacesService* surfaces_service, | 16 ViewportSurface::ViewportSurface(SurfacesService* surfaces_service, |
| 16 Gpu* gpu_service, | 17 Gpu* gpu_service, |
| 17 const gfx::Rect& bounds, | 18 const gfx::Size& size, |
| 18 cc::SurfaceId child_id) | 19 cc::SurfaceId child_id) |
| 19 : gpu_service_(gpu_service), | 20 : gpu_service_(gpu_service), |
| 20 widget_id_(0u), | 21 widget_id_(0u), |
| 21 bounds_(bounds), | 22 size_(size), |
| 22 child_id_(child_id), | 23 child_id_(child_id), |
| 23 weak_factory_(this) { | 24 weak_factory_(this) { |
| 24 surfaces_service->CreateSurfaceConnection( | 25 surfaces_service->CreateSurfaceConnection( |
| 25 base::Bind(&ViewportSurface::OnSurfaceConnectionCreated, | 26 base::Bind(&ViewportSurface::OnSurfaceConnectionCreated, |
| 26 weak_factory_.GetWeakPtr())); | 27 weak_factory_.GetWeakPtr())); |
| 27 } | 28 } |
| 28 | 29 |
| 29 ViewportSurface::~ViewportSurface() { | 30 ViewportSurface::~ViewportSurface() { |
| 30 } | 31 } |
| 31 | 32 |
| 32 void ViewportSurface::SetWidgetId(uint64_t widget_id) { | 33 void ViewportSurface::SetWidgetId(uint64_t widget_id) { |
| 33 widget_id_ = widget_id; | 34 widget_id_ = widget_id; |
| 34 if (id_allocator_) | 35 if (id_allocator_) |
| 35 BindSurfaceToNativeViewport(); | 36 BindSurfaceToNativeViewport(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void ViewportSurface::SetBounds(const gfx::Rect& bounds) { | 39 void ViewportSurface::SetSize(const gfx::Size& size) { |
| 39 if (bounds_ == bounds) | 40 if (size_ == size) |
| 40 return; | 41 return; |
| 41 | 42 |
| 42 if (id_.is_null()) | 43 if (id_.is_null()) |
| 43 return; | 44 return; |
| 44 | 45 |
| 45 surface_->DestroySurface(SurfaceId::From(id_)); | 46 surface_->DestroySurface(SurfaceId::From(id_)); |
| 46 BindSurfaceToNativeViewport(); | 47 if (widget_id_) |
| 48 BindSurfaceToNativeViewport(); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void ViewportSurface::SetChildId(cc::SurfaceId child_id) { | 51 void ViewportSurface::SetChildId(cc::SurfaceId child_id) { |
| 50 child_id_ = child_id; | 52 child_id_ = child_id; |
| 51 SubmitFrame(); | 53 SubmitFrame(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void ViewportSurface::OnSurfaceConnectionCreated(SurfacePtr surface, | 56 void ViewportSurface::OnSurfaceConnectionCreated(SurfacePtr surface, |
| 55 uint32_t id_namespace) { | 57 uint32_t id_namespace) { |
| 56 surface_ = surface.Pass(); | 58 surface_ = surface.Pass(); |
| 59 surface_.set_client(this); |
| 57 id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 60 id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
| 58 if (widget_id_ != 0u) | 61 if (widget_id_ != 0u) |
| 59 BindSurfaceToNativeViewport(); | 62 BindSurfaceToNativeViewport(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 void ViewportSurface::BindSurfaceToNativeViewport() { | 65 void ViewportSurface::BindSurfaceToNativeViewport() { |
| 63 CommandBufferPtr cb; | 66 CommandBufferPtr cb; |
| 64 gpu_service_->CreateOnscreenGLES2Context( | 67 gpu_service_->CreateOnscreenGLES2Context( |
| 65 widget_id_, Size::From(bounds_.size()), Get(&cb)); | 68 widget_id_, Size::From(size_), Get(&cb)); |
| 66 | 69 |
| 67 id_ = id_allocator_->GenerateId(); | 70 id_ = id_allocator_->GenerateId(); |
| 68 surface_->CreateGLES2BoundSurface( | 71 surface_->CreateGLES2BoundSurface( |
| 69 cb.Pass(), SurfaceId::From(id_), Size::From(bounds_.size())); | 72 cb.Pass(), SurfaceId::From(id_), Size::From(size_)); |
| 70 | 73 |
| 71 SubmitFrame(); | 74 SubmitFrame(); |
| 72 } | 75 } |
| 73 | 76 |
| 74 void ViewportSurface::SubmitFrame() { | 77 void ViewportSurface::SubmitFrame() { |
| 75 if (child_id_.is_null() || id_.is_null()) | 78 if (child_id_.is_null() || id_.is_null()) |
| 76 return; | 79 return; |
| 77 | 80 |
| 78 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New(); | 81 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New(); |
| 79 surface_quad_state->surface = SurfaceId::From(child_id_); | 82 surface_quad_state->surface = SurfaceId::From(child_id_); |
| 80 | 83 |
| 84 gfx::Rect bounds(size_); |
| 85 |
| 81 QuadPtr surface_quad = Quad::New(); | 86 QuadPtr surface_quad = Quad::New(); |
| 82 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT; | 87 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT; |
| 83 surface_quad->rect = Rect::From(bounds_); | 88 surface_quad->rect = Rect::From(bounds); |
| 84 surface_quad->opaque_rect = Rect::From(bounds_); | 89 surface_quad->opaque_rect = Rect::From(bounds); |
| 85 surface_quad->visible_rect = Rect::From(bounds_); | 90 surface_quad->visible_rect = Rect::From(bounds); |
| 86 surface_quad->needs_blending = true; | 91 surface_quad->needs_blending = true; |
| 87 surface_quad->shared_quad_state_index = 0; | 92 surface_quad->shared_quad_state_index = 0; |
| 88 surface_quad->surface_quad_state = surface_quad_state.Pass(); | 93 surface_quad->surface_quad_state = surface_quad_state.Pass(); |
| 89 | 94 |
| 90 SharedQuadStatePtr sqs = SharedQuadState::New(); | 95 PassPtr pass = CreateDefaultPass(1, bounds); |
| 91 sqs->content_to_target_transform = Transform::From(gfx::Transform()); | |
| 92 sqs->content_bounds = Size::From(bounds_.size()); | |
| 93 sqs->visible_content_rect = Rect::From(bounds_); | |
| 94 sqs->clip_rect = Rect::From(bounds_); | |
| 95 sqs->is_clipped = false; | |
| 96 sqs->opacity = 1.0f; | |
| 97 sqs->blend_mode = SkXfermode::SK_XFERMODE_kSrcOver_Mode; | |
| 98 sqs->sorting_context_id = 1; | |
| 99 | 96 |
| 100 PassPtr pass = Pass::New(); | |
| 101 pass->id = 1; | |
| 102 pass->output_rect = Rect::From(bounds_); | |
| 103 pass->damage_rect = Rect::From(bounds_); | |
| 104 pass->transform_to_root_target = Transform::From(gfx::Transform()); | |
| 105 pass->has_transparent_background = false; | |
| 106 pass->quads.push_back(surface_quad.Pass()); | 97 pass->quads.push_back(surface_quad.Pass()); |
| 107 pass->shared_quad_states.push_back(sqs.Pass()); | 98 pass->shared_quad_states.push_back(CreateDefaultSQS(size_)); |
| 108 | 99 |
| 109 FramePtr frame = Frame::New(); | 100 FramePtr frame = Frame::New(); |
| 110 frame->passes.push_back(pass.Pass()); | 101 frame->passes.push_back(pass.Pass()); |
| 111 frame->resources.resize(0u); | 102 frame->resources.resize(0u); |
| 112 surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass()); | 103 surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass()); |
| 113 } | 104 } |
| 114 | 105 |
| 115 void ViewportSurface::ReturnResources(Array<ReturnedResourcePtr> resources) { | 106 void ViewportSurface::ReturnResources(Array<ReturnedResourcePtr> resources) { |
| 116 // We never submit resources so we should never get any back. | 107 // We never submit resources so we should never get any back. |
| 117 DCHECK_EQ(0u, resources.size()); | 108 DCHECK_EQ(0u, resources.size()); |
| 118 } | 109 } |
| 119 | 110 |
| 120 } // namespace mojo | 111 } // namespace mojo |
| OLD | NEW |