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 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 Display::Display(DisplayClient* client, | 20 Display::Display(DisplayClient* client, |
21 SurfaceManager* manager, | 21 SurfaceManager* manager, |
22 SharedBitmapManager* bitmap_manager) | 22 SharedBitmapManager* bitmap_manager) |
23 : client_(client), manager_(manager), bitmap_manager_(bitmap_manager) { | 23 : client_(client), |
24 manager_(manager), | |
25 bitmap_manager_(bitmap_manager), | |
26 scheduled_draw_(false), | |
27 weak_ptr_factory_(this) { | |
24 } | 28 } |
25 | 29 |
26 Display::~Display() { | 30 Display::~Display() { |
31 ClearSurfaceList(); | |
27 } | 32 } |
28 | 33 |
29 void Display::Resize(SurfaceId id, const gfx::Size& size) { | 34 void Display::Resize(SurfaceId id, const gfx::Size& size) { |
30 current_surface_id_ = id; | 35 current_surface_id_ = id; |
31 current_surface_size_ = size; | 36 current_surface_size_ = size; |
37 ClearSurfaceList(); | |
38 Draw(); | |
32 } | 39 } |
33 | 40 |
34 void Display::InitializeOutputSurface() { | 41 void Display::InitializeOutputSurface() { |
35 if (output_surface_) | 42 if (output_surface_) |
36 return; | 43 return; |
37 scoped_ptr<OutputSurface> output_surface = client_->CreateOutputSurface(); | 44 scoped_ptr<OutputSurface> output_surface = client_->CreateOutputSurface(); |
38 if (!output_surface->BindToClient(this)) | 45 if (!output_surface->BindToClient(this)) |
39 return; | 46 return; |
40 | 47 |
41 int highp_threshold_min = 0; | 48 int highp_threshold_min = 0; |
(...skipping 29 matching lines...) Expand all Loading... | |
71 return; | 78 return; |
72 renderer_ = renderer.Pass(); | 79 renderer_ = renderer.Pass(); |
73 } | 80 } |
74 | 81 |
75 output_surface_ = output_surface.Pass(); | 82 output_surface_ = output_surface.Pass(); |
76 resource_provider_ = resource_provider.Pass(); | 83 resource_provider_ = resource_provider.Pass(); |
77 aggregator_.reset(new SurfaceAggregator(manager_, resource_provider_.get())); | 84 aggregator_.reset(new SurfaceAggregator(manager_, resource_provider_.get())); |
78 } | 85 } |
79 | 86 |
80 bool Display::Draw() { | 87 bool Display::Draw() { |
88 if (scheduled_draw_) | |
89 return true; | |
90 scheduled_draw_ = true; | |
91 base::MessageLoopProxy::current()->PostTask( | |
jamesr
2014/08/07 21:04:06
the Display should not self-schedule. tell the cli
piman
2014/08/07 21:09:32
drive-by: also going to MessageLoopProxy::current(
| |
92 FROM_HERE, base::Bind(&Display::DoDraw, weak_ptr_factory_.GetWeakPtr())); | |
93 return true; | |
94 } | |
95 | |
96 void Display::DoDraw() { | |
97 TRACE_EVENT0("cc", "Display::DoDraw"); | |
98 scheduled_draw_ = false; | |
81 if (current_surface_id_.is_null()) | 99 if (current_surface_id_.is_null()) |
82 return false; | 100 return; |
83 | 101 |
84 InitializeOutputSurface(); | 102 InitializeOutputSurface(); |
85 if (!output_surface_) | 103 if (!output_surface_) |
86 return false; | 104 return; |
87 | 105 |
106 ClearSurfaceList(); | |
88 scoped_ptr<CompositorFrame> frame = | 107 scoped_ptr<CompositorFrame> frame = |
89 aggregator_->Aggregate(current_surface_id_); | 108 aggregator_->Aggregate(current_surface_id_, &contained_surfaces_); |
109 | |
110 for (std::set<Surface*>::iterator it = contained_surfaces_.begin(); | |
111 it != contained_surfaces_.end(); | |
112 ++it) { | |
113 (*it)->containing_displays().insert(this); | |
114 } | |
90 if (!frame) | 115 if (!frame) |
91 return false; | 116 return; |
92 | 117 |
93 TRACE_EVENT0("cc", "Display::Draw"); | |
94 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 118 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
95 | 119 |
96 // Only reshape when we know we are going to draw. Otherwise, the reshape | 120 // 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 | 121 // can leave the window at the wrong size if we never draw and the proper |
98 // viewport size is never set. | 122 // viewport size is never set. |
99 output_surface_->Reshape(current_surface_size_, 1.f); | 123 output_surface_->Reshape(current_surface_size_, 1.f); |
100 float device_scale_factor = 1.0f; | 124 float device_scale_factor = 1.0f; |
101 gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_); | 125 gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_); |
102 gfx::Rect device_clip_rect = device_viewport_rect; | 126 gfx::Rect device_clip_rect = device_viewport_rect; |
103 bool disable_picture_quad_image_filtering = false; | 127 bool disable_picture_quad_image_filtering = false; |
104 | 128 |
105 renderer_->DecideRenderPassAllocationsForFrame(frame_data->render_pass_list); | 129 renderer_->DecideRenderPassAllocationsForFrame(frame_data->render_pass_list); |
106 renderer_->DrawFrame(&frame_data->render_pass_list, | 130 renderer_->DrawFrame(&frame_data->render_pass_list, |
107 device_scale_factor, | 131 device_scale_factor, |
108 device_viewport_rect, | 132 device_viewport_rect, |
109 device_clip_rect, | 133 device_clip_rect, |
110 disable_picture_quad_image_filtering); | 134 disable_picture_quad_image_filtering); |
111 CompositorFrameMetadata metadata; | 135 CompositorFrameMetadata metadata; |
112 renderer_->SwapBuffers(metadata); | 136 renderer_->SwapBuffers(metadata); |
113 return true; | 137 } |
138 | |
139 void Display::ClearSurfaceList() { | |
140 for (std::set<Surface*>::iterator it = contained_surfaces_.begin(); | |
141 it != contained_surfaces_.end(); | |
142 ++it) { | |
143 (*it)->containing_displays().erase(this); | |
144 } | |
145 | |
146 contained_surfaces_.clear(); | |
114 } | 147 } |
115 | 148 |
116 SurfaceId Display::CurrentSurfaceId() { | 149 SurfaceId Display::CurrentSurfaceId() { |
117 return current_surface_id_; | 150 return current_surface_id_; |
118 } | 151 } |
119 | 152 |
120 } // namespace cc | 153 } // namespace cc |
OLD | NEW |