| 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 "content/browser/compositor/onscreen_display_client.h" | 5 #include "content/browser/compositor/onscreen_display_client.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/output/output_surface.h" | 8 #include "cc/output/output_surface.h" |
| 9 #include "cc/surfaces/surface_factory.h" | 9 #include "cc/surfaces/surface_factory.h" |
| 10 #include "cc/surfaces/surface_manager.h" | 10 #include "cc/surfaces/surface_manager.h" |
| 11 #include "content/browser/compositor/surface_display_output_surface.h" | 11 #include "content/browser/compositor/surface_display_output_surface.h" |
| 12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 13 #include "content/common/host_shared_bitmap_manager.h" | 13 #include "content/common/host_shared_bitmap_manager.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 OnscreenDisplayClient::OnscreenDisplayClient( | 17 OnscreenDisplayClient::OnscreenDisplayClient( |
| 18 scoped_ptr<cc::OutputSurface> output_surface, | 18 scoped_ptr<cc::OutputSurface> output_surface, |
| 19 cc::SurfaceManager* manager, | 19 cc::SurfaceManager* manager, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 21 : output_surface_(output_surface.Pass()), | 21 : output_surface_(output_surface.Pass()), |
| 22 display_(new cc::Display(this, | 22 display_(new cc::Display(this, |
| 23 manager, | 23 manager, |
| 24 HostSharedBitmapManager::current(), | 24 HostSharedBitmapManager::current(), |
| 25 BrowserGpuMemoryBufferManager::current())), | 25 BrowserGpuMemoryBufferManager::current())), |
| 26 task_runner_(task_runner), | 26 task_runner_(task_runner), |
| 27 scheduled_draw_(false), | 27 scheduled_draw_(false), |
| 28 output_surface_lost_(false), |
| 28 deferred_draw_(false), | 29 deferred_draw_(false), |
| 29 pending_frames_(0), | 30 pending_frames_(0), |
| 30 weak_ptr_factory_(this) { | 31 weak_ptr_factory_(this) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 OnscreenDisplayClient::~OnscreenDisplayClient() { | 34 OnscreenDisplayClient::~OnscreenDisplayClient() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 bool OnscreenDisplayClient::Initialize() { | 37 bool OnscreenDisplayClient::Initialize() { |
| 37 return display_->Initialize(output_surface_.Pass()); | 38 return display_->Initialize(output_surface_.Pass()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 void OnscreenDisplayClient::ScheduleDraw() { | 57 void OnscreenDisplayClient::ScheduleDraw() { |
| 57 DCHECK(!deferred_draw_); | 58 DCHECK(!deferred_draw_); |
| 58 DCHECK(!scheduled_draw_); | 59 DCHECK(!scheduled_draw_); |
| 59 scheduled_draw_ = true; | 60 scheduled_draw_ = true; |
| 60 task_runner_->PostTask( | 61 task_runner_->PostTask( |
| 61 FROM_HERE, | 62 FROM_HERE, |
| 62 base::Bind(&OnscreenDisplayClient::Draw, weak_ptr_factory_.GetWeakPtr())); | 63 base::Bind(&OnscreenDisplayClient::Draw, weak_ptr_factory_.GetWeakPtr())); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void OnscreenDisplayClient::OutputSurfaceLost() { | 66 void OnscreenDisplayClient::OutputSurfaceLost() { |
| 67 output_surface_lost_ = true; |
| 66 surface_display_output_surface_->DidLoseOutputSurface(); | 68 surface_display_output_surface_->DidLoseOutputSurface(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void OnscreenDisplayClient::Draw() { | 71 void OnscreenDisplayClient::Draw() { |
| 70 TRACE_EVENT0("content", "OnscreenDisplayClient::Draw"); | 72 TRACE_EVENT0("content", "OnscreenDisplayClient::Draw"); |
| 73 if (output_surface_lost_) |
| 74 return; |
| 71 scheduled_draw_ = false; | 75 scheduled_draw_ = false; |
| 72 display_->Draw(); | 76 display_->Draw(); |
| 73 } | 77 } |
| 74 | 78 |
| 75 void OnscreenDisplayClient::DidSwapBuffers() { | 79 void OnscreenDisplayClient::DidSwapBuffers() { |
| 76 pending_frames_++; | 80 pending_frames_++; |
| 77 } | 81 } |
| 78 | 82 |
| 79 void OnscreenDisplayClient::DidSwapBuffersComplete() { | 83 void OnscreenDisplayClient::DidSwapBuffersComplete() { |
| 80 pending_frames_--; | 84 pending_frames_--; |
| 81 if ((pending_frames_ < display_->GetMaxFramesPending()) && deferred_draw_) { | 85 if ((pending_frames_ < display_->GetMaxFramesPending()) && deferred_draw_) { |
| 82 deferred_draw_ = false; | 86 deferred_draw_ = false; |
| 83 ScheduleDraw(); | 87 ScheduleDraw(); |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 | 90 |
| 87 void OnscreenDisplayClient::SetMemoryPolicy( | 91 void OnscreenDisplayClient::SetMemoryPolicy( |
| 88 const cc::ManagedMemoryPolicy& policy) { | 92 const cc::ManagedMemoryPolicy& policy) { |
| 89 surface_display_output_surface_->SetMemoryPolicy(policy); | 93 surface_display_output_surface_->SetMemoryPolicy(policy); |
| 90 } | 94 } |
| 91 | 95 |
| 92 } // namespace content | 96 } // namespace content |
| OLD | NEW |