| 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 "cc/surfaces/display.h" | 5 #include "cc/surfaces/display.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
| 11 #include "cc/output/direct_renderer.h" | 11 #include "cc/output/direct_renderer.h" |
| 12 #include "cc/output/gl_renderer.h" | 12 #include "cc/output/gl_renderer.h" |
| 13 #include "cc/output/software_renderer.h" | 13 #include "cc/output/software_renderer.h" |
| 14 #include "cc/surfaces/display_client.h" | 14 #include "cc/surfaces/display_client.h" |
| 15 #include "cc/surfaces/surface.h" | 15 #include "cc/surfaces/surface.h" |
| 16 #include "cc/surfaces/surface_aggregator.h" | 16 #include "cc/surfaces/surface_aggregator.h" |
| 17 #include "cc/surfaces/surface_manager.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 | 20 |
| 20 Display::Display(DisplayClient* client, | 21 Display::Display(DisplayClient* client, |
| 21 SurfaceManager* manager, | 22 SurfaceManager* manager, |
| 22 SharedBitmapManager* bitmap_manager) | 23 SharedBitmapManager* bitmap_manager) |
| 23 : client_(client), manager_(manager), bitmap_manager_(bitmap_manager) { | 24 : client_(client), manager_(manager), bitmap_manager_(bitmap_manager) { |
| 25 manager_->AddObserver(this); |
| 24 } | 26 } |
| 25 | 27 |
| 26 Display::~Display() { | 28 Display::~Display() { |
| 29 manager_->RemoveObserver(this); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void Display::Resize(SurfaceId id, const gfx::Size& size) { | 32 void Display::Resize(SurfaceId id, const gfx::Size& size) { |
| 30 current_surface_id_ = id; | 33 current_surface_id_ = id; |
| 31 current_surface_size_ = size; | 34 current_surface_size_ = size; |
| 35 client_->DisplayDamaged(); |
| 32 } | 36 } |
| 33 | 37 |
| 34 void Display::InitializeOutputSurface() { | 38 void Display::InitializeOutputSurface() { |
| 35 if (output_surface_) | 39 if (output_surface_) |
| 36 return; | 40 return; |
| 37 scoped_ptr<OutputSurface> output_surface = client_->CreateOutputSurface(); | 41 scoped_ptr<OutputSurface> output_surface = client_->CreateOutputSurface(); |
| 38 if (!output_surface->BindToClient(this)) | 42 if (!output_surface->BindToClient(this)) |
| 39 return; | 43 return; |
| 40 | 44 |
| 41 int highp_threshold_min = 0; | 45 int highp_threshold_min = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 82 } |
| 79 | 83 |
| 80 bool Display::Draw() { | 84 bool Display::Draw() { |
| 81 if (current_surface_id_.is_null()) | 85 if (current_surface_id_.is_null()) |
| 82 return false; | 86 return false; |
| 83 | 87 |
| 84 InitializeOutputSurface(); | 88 InitializeOutputSurface(); |
| 85 if (!output_surface_) | 89 if (!output_surface_) |
| 86 return false; | 90 return false; |
| 87 | 91 |
| 92 contained_surfaces_.clear(); |
| 93 |
| 88 scoped_ptr<CompositorFrame> frame = | 94 scoped_ptr<CompositorFrame> frame = |
| 89 aggregator_->Aggregate(current_surface_id_); | 95 aggregator_->Aggregate(current_surface_id_, &contained_surfaces_); |
| 90 if (!frame) | 96 if (!frame) |
| 91 return false; | 97 return false; |
| 92 | 98 |
| 93 TRACE_EVENT0("cc", "Display::Draw"); | 99 TRACE_EVENT0("cc", "Display::Draw"); |
| 94 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 100 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
| 95 | 101 |
| 96 // Only reshape when we know we are going to draw. Otherwise, the reshape | 102 // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 97 // can leave the window at the wrong size if we never draw and the proper | 103 // can leave the window at the wrong size if we never draw and the proper |
| 98 // viewport size is never set. | 104 // viewport size is never set. |
| 99 output_surface_->Reshape(current_surface_size_, 1.f); | 105 output_surface_->Reshape(current_surface_size_, 1.f); |
| 100 float device_scale_factor = 1.0f; | 106 float device_scale_factor = 1.0f; |
| 101 gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_); | 107 gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_); |
| 102 gfx::Rect device_clip_rect = device_viewport_rect; | 108 gfx::Rect device_clip_rect = device_viewport_rect; |
| 103 bool disable_picture_quad_image_filtering = false; | 109 bool disable_picture_quad_image_filtering = false; |
| 104 | 110 |
| 105 renderer_->DecideRenderPassAllocationsForFrame(frame_data->render_pass_list); | 111 renderer_->DecideRenderPassAllocationsForFrame(frame_data->render_pass_list); |
| 106 renderer_->DrawFrame(&frame_data->render_pass_list, | 112 renderer_->DrawFrame(&frame_data->render_pass_list, |
| 107 device_scale_factor, | 113 device_scale_factor, |
| 108 device_viewport_rect, | 114 device_viewport_rect, |
| 109 device_clip_rect, | 115 device_clip_rect, |
| 110 disable_picture_quad_image_filtering); | 116 disable_picture_quad_image_filtering); |
| 111 CompositorFrameMetadata metadata; | 117 CompositorFrameMetadata metadata; |
| 112 renderer_->SwapBuffers(metadata); | 118 renderer_->SwapBuffers(metadata); |
| 113 return true; | 119 return true; |
| 114 } | 120 } |
| 115 | 121 |
| 122 void Display::OnSurfaceDamaged(SurfaceId surface) { |
| 123 if (contained_surfaces_.find(surface) != contained_surfaces_.end()) |
| 124 client_->DisplayDamaged(); |
| 125 } |
| 126 |
| 116 SurfaceId Display::CurrentSurfaceId() { | 127 SurfaceId Display::CurrentSurfaceId() { |
| 117 return current_surface_id_; | 128 return current_surface_id_; |
| 118 } | 129 } |
| 119 | 130 |
| 120 } // namespace cc | 131 } // namespace cc |
| OLD | NEW |