OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "remoting/client/plugin/pepper_view.h" | 5 #include "remoting/client/plugin/pepper_view.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 pp::Rect pp_size = view.GetRect(); | 76 pp::Rect pp_size = view.GetRect(); |
77 SkISize new_size_dips = SkISize::Make(pp_size.width(), pp_size.height()); | 77 SkISize new_size_dips = SkISize::Make(pp_size.width(), pp_size.height()); |
78 pp::ViewDev view_dev(view); | 78 pp::ViewDev view_dev(view); |
79 float new_scale = view_dev.GetDeviceScale(); | 79 float new_scale = view_dev.GetDeviceScale(); |
80 | 80 |
81 if (view_size_dips_ != new_size_dips || view_scale_ != new_scale) { | 81 if (view_size_dips_ != new_size_dips || view_scale_ != new_scale) { |
82 view_changed = true; | 82 view_changed = true; |
83 view_scale_ = new_scale; | 83 view_scale_ = new_scale; |
84 view_size_dips_ = new_size_dips; | 84 view_size_dips_ = new_size_dips; |
85 view_size_ = SkISize::Make(ceilf(view_size_dips_.width() * view_scale_), | |
86 ceilf(view_size_dips_.height() * view_scale_)); | |
87 | 85 |
86 // If |view_scale_| is > 1.0 then the device is high-DPI, and there are | |
87 // actually |view_scale_| physical pixels for every one Density Independent | |
88 // Pixel (DIP). If we specify a scale of 1.0 to Graphics2D then we can | |
89 // render at DIP resolution and let PPAPI up-scale for high-DPI devices. | |
90 // Note that |view_scale_| is DIPS->pixels, |scale| is pixels->DIPS. | |
91 float scale = 1.0f; | |
92 view_size_ = view_size_dips_; | |
93 | |
94 // If the view's DIP dimensions don't match the source then let the frame | |
95 // producer do the scaling, and render at device resolution. | |
96 if (view_size_dips_ != source_size_) { | |
97 scale = 1.0f / view_scale_; | |
98 view_size_ = SkISize::Make(ceilf(view_size_dips_.width() * view_scale_), | |
99 ceilf(view_size_dips_.height() * view_scale_)); | |
100 } | |
101 | |
102 // Create a 2D rendering context at the chosen frame dimensions. | |
88 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); | 103 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); |
89 graphics2d_ = pp::Graphics2D(instance_, pp_size, true); | 104 graphics2d_ = pp::Graphics2D(instance_, pp_size, true); |
90 | 105 |
91 // Ideally we would always let Graphics2D scale us, but the output quality | |
92 // is lousy, so we don't. | |
Jamie
2012/12/18 19:45:32
I take it this comment is no longer true?
Wez
2012/12/18 19:47:23
No; it's still true for non-integer scale factors
| |
93 pp::Graphics2D_Dev graphics2d_dev(graphics2d_); | 106 pp::Graphics2D_Dev graphics2d_dev(graphics2d_); |
94 graphics2d_dev.SetScale(1.0f / view_scale_); | 107 graphics2d_dev.SetScale(scale); |
95 | 108 |
96 bool result = instance_->BindGraphics(graphics2d_); | 109 bool result = instance_->BindGraphics(graphics2d_); |
97 | 110 |
98 // There is no good way to handle this error currently. | 111 // There is no good way to handle this error currently. |
99 DCHECK(result) << "Couldn't bind the device context."; | 112 DCHECK(result) << "Couldn't bind the device context."; |
100 } | 113 } |
101 | 114 |
102 pp::Rect pp_clip = view.GetClipRect(); | 115 pp::Rect pp_clip = view.GetClipRect(); |
103 SkIRect new_clip = SkIRect::MakeLTRB(floorf(pp_clip.x() * view_scale_), | 116 SkIRect new_clip = SkIRect::MakeLTRB(floorf(pp_clip.x() * view_scale_), |
104 floorf(pp_clip.y() * view_scale_), | 117 floorf(pp_clip.y() * view_scale_), |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 289 |
277 // If there is a buffer queued for rendering then render it now. | 290 // If there is a buffer queued for rendering then render it now. |
278 if (merge_buffer_ != NULL) { | 291 if (merge_buffer_ != NULL) { |
279 buffer = merge_buffer_; | 292 buffer = merge_buffer_; |
280 merge_buffer_ = NULL; | 293 merge_buffer_ = NULL; |
281 FlushBuffer(merge_clip_area_, buffer, merge_region_); | 294 FlushBuffer(merge_clip_area_, buffer, merge_region_); |
282 } | 295 } |
283 } | 296 } |
284 | 297 |
285 } // namespace remoting | 298 } // namespace remoting |
OLD | NEW |