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