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 13 namespace content { 14 15 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( 16 cc::SurfaceManager* surface_manager, 17 uint32_t surface_id_namespace, 18 const scoped_refptr<cc::ContextProvider>& context_provider) 19 : cc::OutputSurface(context_provider, 20 scoped_ptr<cc::SoftwareOutputDevice>()), 21 display_(NULL), 22 surface_manager_(surface_manager), 23 factory_(surface_manager, this), 24 allocator_(surface_id_namespace) { 25 capabilities_.delegated_rendering = true; 26 capabilities_.max_frames_pending = 1; 27 } 28 29 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { 30 client_ = NULL; 31 if (!surface_id_.is_null()) { 32 factory_.Destroy(surface_id_); 33 } 34 } 35 36 void SurfaceDisplayOutputSurface::ReceivedVSyncParameters( 37 base::TimeTicks timebase, 38 base::TimeDelta interval) { 39 CommitVSyncParameters(timebase, interval); 40 } 41 42 void SurfaceDisplayOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { 43 gfx::Size frame_size = 44 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); 45 if (frame_size != display_size_) { 46 if (!surface_id_.is_null()) { 47 factory_.Destroy(surface_id_); 48 } 49 surface_id_ = allocator_.GenerateId(); 50 factory_.Create(surface_id_, frame_size); 51 display_size_ = frame_size; 52 display_->Resize(surface_id_, frame_size); 53 } 54 55 scoped_ptr<cc::CompositorFrame> frame_copy(new cc::CompositorFrame()); 56 frame->AssignTo(frame_copy.get()); 57 factory_.SubmitFrame( 58 surface_id_, 59 frame_copy.Pass(), 60 base::Bind(&SurfaceDisplayOutputSurface::SwapBuffersComplete, 61 base::Unretained(this))); 62 63 client_->DidSwapBuffers(); 64 } 65 66 void SurfaceDisplayOutputSurface::ReturnResources( 67 const cc::ReturnedResourceArray& resources) { 68 cc::CompositorFrameAck ack; 69 ack.resources = resources; 70 if (client_) 71 client_->ReclaimResources(&ack); 72 } 73 74 void SurfaceDisplayOutputSurface::SwapBuffersComplete() { 75 client_->DidSwapBuffersComplete(); 76 } 77 78 } // namespace content 79