| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/surfaces/surface_display_output_surface.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "cc/output/compositor_frame.h" | |
| 9 #include "cc/output/compositor_frame_ack.h" | |
| 10 #include "cc/surfaces/display.h" | |
| 11 #include "cc/surfaces/onscreen_display_client.h" | |
| 12 #include "cc/surfaces/surface.h" | |
| 13 #include "cc/surfaces/surface_manager.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( | |
| 18 SurfaceManager* surface_manager, | |
| 19 SurfaceIdAllocator* allocator, | |
| 20 const scoped_refptr<ContextProvider>& context_provider) | |
| 21 : OutputSurface(context_provider), | |
| 22 display_client_(NULL), | |
| 23 surface_manager_(surface_manager), | |
| 24 factory_(surface_manager, this), | |
| 25 allocator_(allocator) { | |
| 26 capabilities_.delegated_rendering = true; | |
| 27 capabilities_.max_frames_pending = 1; | |
| 28 capabilities_.adjust_deadline_for_parent = true; | |
| 29 capabilities_.can_force_reclaim_resources = true; | |
| 30 } | |
| 31 | |
| 32 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { | |
| 33 client_ = NULL; | |
| 34 if (!surface_id_.is_null()) { | |
| 35 factory_.Destroy(surface_id_); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters( | |
| 40 base::TimeTicks timebase, | |
| 41 base::TimeDelta interval) { | |
| 42 CommitVSyncParameters(timebase, interval); | |
| 43 } | |
| 44 | |
| 45 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame* frame) { | |
| 46 gfx::Size frame_size = | |
| 47 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
| 48 if (frame_size.IsEmpty() || frame_size != display_size_) { | |
| 49 if (!surface_id_.is_null()) { | |
| 50 factory_.Destroy(surface_id_); | |
| 51 } | |
| 52 surface_id_ = allocator_->GenerateId(); | |
| 53 factory_.Create(surface_id_); | |
| 54 display_size_ = frame_size; | |
| 55 } | |
| 56 display_client_->display()->SetSurfaceId(surface_id_, | |
| 57 frame->metadata.device_scale_factor); | |
| 58 | |
| 59 scoped_ptr<CompositorFrame> frame_copy(new CompositorFrame()); | |
| 60 frame->AssignTo(frame_copy.get()); | |
| 61 factory_.SubmitFrame( | |
| 62 surface_id_, frame_copy.Pass(), | |
| 63 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, | |
| 64 base::Unretained(this))); | |
| 65 | |
| 66 client_->DidSwapBuffers(); | |
| 67 } | |
| 68 | |
| 69 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { | |
| 70 DCHECK(client); | |
| 71 DCHECK(display_client_); | |
| 72 client_ = client; | |
| 73 // Avoid initializing GL context here, as this should be sharing the | |
| 74 // Display's context. | |
| 75 return display_client_->Initialize(); | |
| 76 } | |
| 77 | |
| 78 void SurfaceDisplayOutputSurface::ForceReclaimResources() { | |
| 79 if (!surface_id_.is_null()) { | |
| 80 scoped_ptr<CompositorFrame> empty_frame(new CompositorFrame()); | |
| 81 empty_frame->delegated_frame_data.reset(new DelegatedFrameData); | |
| 82 factory_.SubmitFrame(surface_id_, empty_frame.Pass(), | |
| 83 SurfaceFactory::DrawCallback()); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void SurfaceDisplayOutputSurface::ReturnResources( | |
| 88 const ReturnedResourceArray& resources) { | |
| 89 CompositorFrameAck ack; | |
| 90 ack.resources = resources; | |
| 91 if (client_) | |
| 92 client_->ReclaimResources(&ack); | |
| 93 } | |
| 94 | |
| 95 void SurfaceDisplayOutputSurface::SwapBuffersComplete(SurfaceDrawStatus drawn) { | |
| 96 if (client_ && !display_client_->output_surface_lost()) | |
| 97 client_->DidSwapBuffersComplete(); | |
| 98 } | |
| 99 | |
| 100 } // namespace cc | |
| OLD | NEW |