Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(898)

Side by Side Diff: cc/layers/heads_up_display_layer_impl.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layers/heads_up_display_layer_impl.h" 5 #include "cc/layers/heads_up_display_layer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 10 matching lines...) Expand all
21 #include "cc/trees/layer_tree_impl.h" 21 #include "cc/trees/layer_tree_impl.h"
22 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
23 #include "third_party/khronos/GLES2/gl2.h" 23 #include "third_party/khronos/GLES2/gl2.h"
24 #include "third_party/khronos/GLES2/gl2ext.h" 24 #include "third_party/khronos/GLES2/gl2ext.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/skia/include/core/SkPaint.h" 26 #include "third_party/skia/include/core/SkPaint.h"
27 #include "third_party/skia/include/core/SkTypeface.h" 27 #include "third_party/skia/include/core/SkTypeface.h"
28 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 28 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
29 #include "ui/gfx/geometry/point.h" 29 #include "ui/gfx/geometry/point.h"
30 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
31 #include "ui/gfx/geometry/size_conversions.h"
31 32
32 namespace cc { 33 namespace cc {
33 34
34 static inline SkPaint CreatePaint() { 35 static inline SkPaint CreatePaint() {
35 SkPaint paint; 36 SkPaint paint;
36 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16) 37 #if (SK_R32_SHIFT || SK_B32_SHIFT != 16)
37 // The SkCanvas is in RGBA but the shader is expecting BGRA, so we need to 38 // The SkCanvas is in RGBA but the shader is expecting BGRA, so we need to
38 // swizzle our colors when drawing to the SkCanvas. 39 // swizzle our colors when drawing to the SkCanvas.
39 SkColorMatrix swizzle_matrix; 40 SkColorMatrix swizzle_matrix;
40 for (int i = 0; i < 20; ++i) 41 for (int i = 0; i < 20; ++i)
(...skipping 21 matching lines...) Expand all
62 63
63 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { 64 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
64 double target_upper_bound = std::max(max, default_upper_bound); 65 double target_upper_bound = std::max(max, default_upper_bound);
65 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; 66 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5;
66 return current_upper_bound; 67 return current_upper_bound;
67 } 68 }
68 69
69 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, 70 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl,
70 int id) 71 int id)
71 : LayerImpl(tree_impl, id), 72 : LayerImpl(tree_impl, id),
73 internal_contents_scale_(1.f),
72 fps_graph_(60.0, 80.0), 74 fps_graph_(60.0, 80.0),
73 paint_time_graph_(16.0, 48.0), 75 paint_time_graph_(16.0, 48.0),
74 fade_step_(0) { 76 fade_step_(0) {
75 } 77 }
76 78
77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} 79 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
78 80
79 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( 81 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl(
80 LayerTreeImpl* tree_impl) { 82 LayerTreeImpl* tree_impl) {
81 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()); 83 return HeadsUpDisplayLayerImpl::Create(tree_impl, id());
82 } 84 }
83 85
84 void HeadsUpDisplayLayerImpl::AcquireResource( 86 void HeadsUpDisplayLayerImpl::AcquireResource(
85 ResourceProvider* resource_provider) { 87 ResourceProvider* resource_provider) {
86 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); 88 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin();
87 it != resources_.end(); 89 it != resources_.end();
88 ++it) { 90 ++it) {
89 if (!resource_provider->InUseByConsumer((*it)->id())) { 91 if (!resource_provider->InUseByConsumer((*it)->id())) {
90 resources_.swap(it, resources_.end() - 1); 92 resources_.swap(it, resources_.end() - 1);
91 return; 93 return;
92 } 94 }
93 } 95 }
94 96
95 scoped_ptr<ScopedResource> resource = 97 scoped_ptr<ScopedResource> resource =
96 ScopedResource::Create(resource_provider); 98 ScopedResource::Create(resource_provider);
97 resource->Allocate( 99 resource->Allocate(internal_content_bounds_,
98 content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888); 100 ResourceProvider::TextureHintImmutable, RGBA_8888);
99 resources_.push_back(resource.Pass()); 101 resources_.push_back(resource.Pass());
100 } 102 }
101 103
102 class ResourceSizeIsEqualTo { 104 class ResourceSizeIsEqualTo {
103 public: 105 public:
104 explicit ResourceSizeIsEqualTo(const gfx::Size& size_) 106 explicit ResourceSizeIsEqualTo(const gfx::Size& size_)
105 : compare_size_(size_) {} 107 : compare_size_(size_) {}
106 108
107 bool operator()(const ScopedResource* resource) { 109 bool operator()(const ScopedResource* resource) {
108 return resource->size() == compare_size_; 110 return resource->size() == compare_size_;
109 } 111 }
110 112
111 private: 113 private:
112 const gfx::Size compare_size_; 114 const gfx::Size compare_size_;
113 }; 115 };
114 116
115 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( 117 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources(
116 ResourceProvider* resource_provider) { 118 ResourceProvider* resource_provider) {
117 ScopedPtrVector<ScopedResource>::iterator it_erase = 119 ScopedPtrVector<ScopedResource>::iterator it_erase =
118 resources_.partition(ResourceSizeIsEqualTo(content_bounds())); 120 resources_.partition(ResourceSizeIsEqualTo(internal_content_bounds_));
119 resources_.erase(it_erase, resources_.end()); 121 resources_.erase(it_erase, resources_.end());
120 } 122 }
121 123
122 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, 124 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
123 ResourceProvider* resource_provider) { 125 ResourceProvider* resource_provider) {
124 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) 126 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
125 return false; 127 return false;
126 128
129 internal_contents_scale_ = draw_properties().ideal_contents_scale;
130 internal_content_bounds_ =
131 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), internal_contents_scale_));
132
127 ReleaseUnmatchedSizeResources(resource_provider); 133 ReleaseUnmatchedSizeResources(resource_provider);
128 AcquireResource(resource_provider); 134 AcquireResource(resource_provider);
129 return LayerImpl::WillDraw(draw_mode, resource_provider); 135 return LayerImpl::WillDraw(draw_mode, resource_provider);
130 } 136 }
131 137
132 void HeadsUpDisplayLayerImpl::AppendQuads( 138 void HeadsUpDisplayLayerImpl::AppendQuads(
133 RenderPass* render_pass, 139 RenderPass* render_pass,
134 const Occlusion& occlusion_in_content_space,
135 AppendQuadsData* append_quads_data) { 140 AppendQuadsData* append_quads_data) {
136 if (!resources_.back()->id()) 141 if (!resources_.back()->id())
137 return; 142 return;
138 143
139 SharedQuadState* shared_quad_state = 144 SharedQuadState* shared_quad_state =
140 render_pass->CreateAndAppendSharedQuadState(); 145 render_pass->CreateAndAppendSharedQuadState();
141 PopulateSharedQuadState(shared_quad_state); 146 PopulateScaledSharedQuadState(shared_quad_state, internal_contents_scale_);
142 147
143 gfx::Rect quad_rect(content_bounds()); 148 gfx::Rect quad_rect(internal_content_bounds_);
144 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); 149 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect());
145 gfx::Rect visible_quad_rect(quad_rect); 150 gfx::Rect visible_quad_rect(quad_rect);
146 bool premultiplied_alpha = true; 151 bool premultiplied_alpha = true;
147 gfx::PointF uv_top_left(0.f, 0.f); 152 gfx::PointF uv_top_left(0.f, 0.f);
148 gfx::PointF uv_bottom_right(1.f, 1.f); 153 gfx::PointF uv_bottom_right(1.f, 1.f);
149 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f }; 154 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f };
150 bool flipped = false; 155 bool flipped = false;
151 bool nearest_neighbor = false; 156 bool nearest_neighbor = false;
152 TextureDrawQuad* quad = 157 TextureDrawQuad* quad =
153 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); 158 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
(...skipping 16 matching lines...) Expand all
170 ResourceProvider* resource_provider) { 175 ResourceProvider* resource_provider) {
171 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) 176 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id())
172 return; 177 return;
173 178
174 SkISize canvas_size; 179 SkISize canvas_size;
175 if (hud_surface_) 180 if (hud_surface_)
176 canvas_size = hud_surface_->getCanvas()->getDeviceSize(); 181 canvas_size = hud_surface_->getCanvas()->getDeviceSize();
177 else 182 else
178 canvas_size.set(0, 0); 183 canvas_size.set(0, 0);
179 184
180 if (canvas_size.width() != content_bounds().width() || 185 if (canvas_size.width() != internal_content_bounds_.width() ||
181 canvas_size.height() != content_bounds().height() || !hud_surface_) { 186 canvas_size.height() != internal_content_bounds_.height() ||
187 !hud_surface_) {
182 TRACE_EVENT0("cc", "ResizeHudCanvas"); 188 TRACE_EVENT0("cc", "ResizeHudCanvas");
183 189
184 hud_surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul( 190 hud_surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul(
185 content_bounds().width(), content_bounds().height())); 191 internal_content_bounds_.width(), internal_content_bounds_.height()));
186 } 192 }
187 193
188 UpdateHudContents(); 194 UpdateHudContents();
189 195
190 { 196 {
191 TRACE_EVENT0("cc", "DrawHudContents"); 197 TRACE_EVENT0("cc", "DrawHudContents");
192 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); 198 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0));
193 hud_surface_->getCanvas()->save(); 199 hud_surface_->getCanvas()->save();
194 hud_surface_->getCanvas()->scale(contents_scale_x(), contents_scale_y()); 200 hud_surface_->getCanvas()->scale(internal_contents_scale_,
201 internal_contents_scale_);
195 202
196 DrawHudContents(hud_surface_->getCanvas()); 203 DrawHudContents(hud_surface_->getCanvas());
197 204
198 hud_surface_->getCanvas()->restore(); 205 hud_surface_->getCanvas()->restore();
199 } 206 }
200 207
201 TRACE_EVENT0("cc", "UploadHudTexture"); 208 TRACE_EVENT0("cc", "UploadHudTexture");
202 SkImageInfo info; 209 SkImageInfo info;
203 size_t row_bytes = 0; 210 size_t row_bytes = 0;
204 const void* pixels = hud_surface_->getCanvas()->peekPixels(&info, &row_bytes); 211 const void* pixels = hud_surface_->getCanvas()->peekPixels(&info, &row_bytes);
205 DCHECK(pixels); 212 DCHECK(pixels);
206 gfx::Rect content_rect(content_bounds()); 213 gfx::Rect content_rect(internal_content_bounds_);
207 DCHECK(info.colorType() == kN32_SkColorType); 214 DCHECK(info.colorType() == kN32_SkColorType);
208 resource_provider->SetPixels(resources_.back()->id(), 215 resource_provider->SetPixels(resources_.back()->id(),
209 static_cast<const uint8_t*>(pixels), 216 static_cast<const uint8_t*>(pixels),
210 content_rect, 217 content_rect,
211 content_rect, 218 content_rect,
212 gfx::Vector2d()); 219 gfx::Vector2d());
213 } 220 }
214 221
215 void HeadsUpDisplayLayerImpl::ReleaseResources() { 222 void HeadsUpDisplayLayerImpl::ReleaseResources() {
216 resources_.clear(); 223 resources_.clear();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 677 }
671 678
672 void HeadsUpDisplayLayerImpl::DrawDebugRect( 679 void HeadsUpDisplayLayerImpl::DrawDebugRect(
673 SkCanvas* canvas, 680 SkCanvas* canvas,
674 SkPaint* paint, 681 SkPaint* paint,
675 const DebugRect& rect, 682 const DebugRect& rect,
676 SkColor stroke_color, 683 SkColor stroke_color,
677 SkColor fill_color, 684 SkColor fill_color,
678 float stroke_width, 685 float stroke_width,
679 const std::string& label_text) const { 686 const std::string& label_text) const {
680 gfx::Rect debug_layer_rect = gfx::ScaleToEnclosingRect( 687 gfx::Rect debug_layer_rect =
681 rect.rect, 1.0 / contents_scale_x(), 1.0 / contents_scale_y()); 688 gfx::ScaleToEnclosingRect(rect.rect, 1.0 / internal_contents_scale_,
689 1.0 / internal_contents_scale_);
682 SkIRect sk_rect = RectToSkIRect(debug_layer_rect); 690 SkIRect sk_rect = RectToSkIRect(debug_layer_rect);
683 paint->setColor(fill_color); 691 paint->setColor(fill_color);
684 paint->setStyle(SkPaint::kFill_Style); 692 paint->setStyle(SkPaint::kFill_Style);
685 canvas->drawIRect(sk_rect, *paint); 693 canvas->drawIRect(sk_rect, *paint);
686 694
687 paint->setColor(stroke_color); 695 paint->setColor(stroke_color);
688 paint->setStyle(SkPaint::kStroke_Style); 696 paint->setStyle(SkPaint::kStroke_Style);
689 paint->setStrokeWidth(SkFloatToScalar(stroke_width)); 697 paint->setStrokeWidth(SkFloatToScalar(stroke_width));
690 canvas->drawIRect(sk_rect, *paint); 698 canvas->drawIRect(sk_rect, *paint);
691 699
692 if (label_text.length()) { 700 if (label_text.length()) {
693 const int kFontHeight = 12; 701 const int kFontHeight = 12;
694 const int kPadding = 3; 702 const int kPadding = 3;
695 703
696 // The debug_layer_rect may be huge, and converting to a floating point may 704 // The debug_layer_rect may be huge, and converting to a floating point may
697 // be lossy, so intersect with the HUD layer bounds first to prevent that. 705 // be lossy, so intersect with the HUD layer bounds first to prevent that.
698 gfx::Rect clip_rect = debug_layer_rect; 706 gfx::Rect clip_rect = debug_layer_rect;
699 clip_rect.Intersect(gfx::Rect(content_bounds())); 707 clip_rect.Intersect(gfx::Rect(internal_content_bounds_));
700 SkRect sk_clip_rect = RectToSkRect(clip_rect); 708 SkRect sk_clip_rect = RectToSkRect(clip_rect);
701 709
702 canvas->save(); 710 canvas->save();
703 canvas->clipRect(sk_clip_rect); 711 canvas->clipRect(sk_clip_rect);
704 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); 712 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y());
705 713
706 SkPaint label_paint = CreatePaint(); 714 SkPaint label_paint = CreatePaint();
707 label_paint.setTextSize(kFontHeight); 715 label_paint.setTextSize(kFontHeight);
708 label_paint.setTypeface(layer_tree_impl()->settings().hud_typeface.get()); 716 label_paint.setTypeface(layer_tree_impl()->settings().hud_typeface.get());
709 label_paint.setColor(stroke_color); 717 label_paint.setColor(stroke_color);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 case REPLICA_SCREEN_SPACE_RECT_TYPE: 765 case REPLICA_SCREEN_SPACE_RECT_TYPE:
758 stroke_color = DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor(); 766 stroke_color = DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor();
759 fill_color = DebugColors::ScreenSpaceSurfaceReplicaRectFillColor(); 767 fill_color = DebugColors::ScreenSpaceSurfaceReplicaRectFillColor();
760 stroke_width = DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth(); 768 stroke_width = DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth();
761 break; 769 break;
762 case SCREEN_SPACE_RECT_TYPE: 770 case SCREEN_SPACE_RECT_TYPE:
763 stroke_color = DebugColors::ScreenSpaceLayerRectBorderColor(); 771 stroke_color = DebugColors::ScreenSpaceLayerRectBorderColor();
764 fill_color = DebugColors::ScreenSpaceLayerRectFillColor(); 772 fill_color = DebugColors::ScreenSpaceLayerRectFillColor();
765 stroke_width = DebugColors::ScreenSpaceLayerRectBorderWidth(); 773 stroke_width = DebugColors::ScreenSpaceLayerRectBorderWidth();
766 break; 774 break;
767 case OCCLUDING_RECT_TYPE:
768 stroke_color = DebugColors::OccludingRectBorderColor();
769 fill_color = DebugColors::OccludingRectFillColor();
770 stroke_width = DebugColors::OccludingRectBorderWidth();
771 break;
772 case NONOCCLUDING_RECT_TYPE:
773 stroke_color = DebugColors::NonOccludingRectBorderColor();
774 fill_color = DebugColors::NonOccludingRectFillColor();
775 stroke_width = DebugColors::NonOccludingRectBorderWidth();
776 break;
777 case TOUCH_EVENT_HANDLER_RECT_TYPE: 775 case TOUCH_EVENT_HANDLER_RECT_TYPE:
778 stroke_color = DebugColors::TouchEventHandlerRectBorderColor(); 776 stroke_color = DebugColors::TouchEventHandlerRectBorderColor();
779 fill_color = DebugColors::TouchEventHandlerRectFillColor(); 777 fill_color = DebugColors::TouchEventHandlerRectFillColor();
780 stroke_width = DebugColors::TouchEventHandlerRectBorderWidth(); 778 stroke_width = DebugColors::TouchEventHandlerRectBorderWidth();
781 label_text = "touch event listener"; 779 label_text = "touch event listener";
782 break; 780 break;
783 case WHEEL_EVENT_HANDLER_RECT_TYPE: 781 case WHEEL_EVENT_HANDLER_RECT_TYPE:
784 stroke_color = DebugColors::WheelEventHandlerRectBorderColor(); 782 stroke_color = DebugColors::WheelEventHandlerRectBorderColor();
785 fill_color = DebugColors::WheelEventHandlerRectFillColor(); 783 fill_color = DebugColors::WheelEventHandlerRectFillColor();
786 stroke_width = DebugColors::WheelEventHandlerRectBorderWidth(); 784 stroke_width = DebugColors::WheelEventHandlerRectBorderWidth();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 ""); 829 "");
832 } 830 }
833 } 831 }
834 } 832 }
835 833
836 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { 834 const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const {
837 return "cc::HeadsUpDisplayLayerImpl"; 835 return "cc::HeadsUpDisplayLayerImpl";
838 } 836 }
839 837
840 void HeadsUpDisplayLayerImpl::AsValueInto( 838 void HeadsUpDisplayLayerImpl::AsValueInto(
841 base::debug::TracedValue* dict) const { 839 base::trace_event::TracedValue* dict) const {
842 LayerImpl::AsValueInto(dict); 840 LayerImpl::AsValueInto(dict);
843 dict->SetString("layer_name", "Heads Up Display Layer"); 841 dict->SetString("layer_name", "Heads Up Display Layer");
844 } 842 }
845 843
846 } // namespace cc 844 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.h ('k') | cc/layers/heads_up_display_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698