Chromium Code Reviews| 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" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "ppapi/cpp/completion_callback.h" | 12 #include "ppapi/cpp/completion_callback.h" |
| 13 #include "ppapi/cpp/graphics_2d.h" | 13 #include "ppapi/cpp/dev/graphics_2d_dev.h" |
| 14 #include "ppapi/cpp/dev/view_dev.h" | |
| 14 #include "ppapi/cpp/image_data.h" | 15 #include "ppapi/cpp/image_data.h" |
| 15 #include "ppapi/cpp/point.h" | 16 #include "ppapi/cpp/point.h" |
| 16 #include "ppapi/cpp/rect.h" | 17 #include "ppapi/cpp/rect.h" |
| 17 #include "ppapi/cpp/size.h" | 18 #include "ppapi/cpp/size.h" |
| 18 #include "remoting/base/util.h" | 19 #include "remoting/base/util.h" |
| 19 #include "remoting/client/chromoting_stats.h" | 20 #include "remoting/client/chromoting_stats.h" |
| 20 #include "remoting/client/client_context.h" | 21 #include "remoting/client/client_context.h" |
| 21 #include "remoting/client/frame_producer.h" | 22 #include "remoting/client/frame_producer.h" |
| 22 #include "remoting/client/plugin/chromoting_instance.h" | 23 #include "remoting/client/plugin/chromoting_instance.h" |
| 23 #include "remoting/client/plugin/pepper_util.h" | 24 #include "remoting/client/plugin/pepper_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 ClientContext* context, | 71 ClientContext* context, |
| 71 FrameProducer* producer) | 72 FrameProducer* producer) |
| 72 : instance_(instance), | 73 : instance_(instance), |
| 73 context_(context), | 74 context_(context), |
| 74 producer_(producer), | 75 producer_(producer), |
| 75 merge_buffer_(NULL), | 76 merge_buffer_(NULL), |
| 76 merge_clip_area_(SkIRect::MakeEmpty()), | 77 merge_clip_area_(SkIRect::MakeEmpty()), |
| 77 view_size_(SkISize::Make(0, 0)), | 78 view_size_(SkISize::Make(0, 0)), |
| 78 clip_area_(SkIRect::MakeEmpty()), | 79 clip_area_(SkIRect::MakeEmpty()), |
| 79 source_size_(SkISize::Make(0, 0)), | 80 source_size_(SkISize::Make(0, 0)), |
| 81 view_size_dips_(SkISize::Make(0, 0)), | |
| 82 view_scale_(1.0f), | |
| 80 flush_pending_(false), | 83 flush_pending_(false), |
| 81 is_initialized_(false), | 84 is_initialized_(false), |
| 82 frame_received_(false) { | 85 frame_received_(false) { |
| 83 } | 86 } |
| 84 | 87 |
| 85 PepperView::~PepperView() { | 88 PepperView::~PepperView() { |
| 86 DCHECK(merge_buffer_ == NULL); | 89 DCHECK(merge_buffer_ == NULL); |
| 87 DCHECK(buffers_.empty()); | 90 DCHECK(buffers_.empty()); |
| 88 } | 91 } |
| 89 | 92 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 } | 150 } |
| 148 | 151 |
| 149 protocol::ClipboardStub* PepperView::GetClipboardStub() { | 152 protocol::ClipboardStub* PepperView::GetClipboardStub() { |
| 150 return instance_; | 153 return instance_; |
| 151 } | 154 } |
| 152 | 155 |
| 153 protocol::CursorShapeStub* PepperView::GetCursorShapeStub() { | 156 protocol::CursorShapeStub* PepperView::GetCursorShapeStub() { |
| 154 return instance_; | 157 return instance_; |
| 155 } | 158 } |
| 156 | 159 |
| 157 void PepperView::SetView(const SkISize& view_size, const SkIRect& clip_area) { | 160 void PepperView::SetView(const pp::View& view) { |
| 158 bool view_changed = false; | 161 bool view_changed = false; |
| 159 | 162 |
| 160 if (view_size_ != view_size) { | 163 pp::ViewDev view_dev(view); |
| 164 | |
| 165 pp::Rect pp_size = view.GetRect(); | |
| 166 SkISize new_size_dips = SkISize::Make(pp_size.width(), pp_size.height()); | |
| 167 | |
| 168 if (view_size_dips_ != new_size_dips || | |
| 169 view_dev.GetDeviceScale() != view_scale_) { | |
| 161 view_changed = true; | 170 view_changed = true; |
| 162 view_size_ = view_size; | 171 view_scale_ = view_dev.GetDeviceScale(); |
|
Sergey Ulanov
2012/07/19 17:50:23
nit: maybe call GetDeviceScale only once and save
Wez
2012/07/20 00:01:59
Done.
| |
| 172 view_size_dips_ = new_size_dips; | |
| 173 view_size_ = SkISize::Make(ceilf(view_size_dips_.width() * view_scale_), | |
| 174 ceilf(view_size_dips_.height() * view_scale_)); | |
| 163 | 175 |
| 164 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); | 176 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); |
| 165 graphics2d_ = pp::Graphics2D(instance_, pp_size, true); | 177 pp::Graphics2DDev graphics2d = pp::Graphics2D(instance_, pp_size, true); |
|
Sergey Ulanov
2012/07/19 17:50:23
nit: might be better if you assign graphics2d_ fir
Wez
2012/07/20 00:01:59
Done.
| |
| 178 | |
| 179 // Ideally we would always let Graphics2D scale us, but the output quality | |
| 180 // is lousy, so we don't. | |
| 181 graphics2d.SetScale(1.0f / view_scale_); | |
| 182 | |
| 183 graphics2d_ = graphics2d; | |
| 166 bool result = instance_->BindGraphics(graphics2d_); | 184 bool result = instance_->BindGraphics(graphics2d_); |
| 167 | 185 |
| 168 // There is no good way to handle this error currently. | 186 // There is no good way to handle this error currently. |
| 169 DCHECK(result) << "Couldn't bind the device context."; | 187 DCHECK(result) << "Couldn't bind the device context."; |
| 170 } | 188 } |
| 171 | 189 |
| 172 if (clip_area_ != clip_area) { | 190 pp::Rect pp_clip = view.GetClipRect(); |
| 191 SkIRect new_clip = SkIRect::MakeLTRB(floorf(pp_clip.x() * view_scale_), | |
| 192 floorf(pp_clip.y() * view_scale_), | |
| 193 ceilf(pp_clip.right() * view_scale_), | |
| 194 ceilf(pp_clip.bottom() * view_scale_); | |
| 195 if (clip_area_ != new_clip) { | |
| 173 view_changed = true; | 196 view_changed = true; |
| 174 | 197 |
| 175 // YUV to RGB conversion may require even X and Y coordinates for | 198 // YUV to RGB conversion may require even X and Y coordinates for |
| 176 // the top left corner of the clipping area. | 199 // the top left corner of the clipping area. |
| 177 clip_area_ = AlignRect(clip_area); | 200 clip_area_ = AlignRect(new_clip); |
| 178 clip_area_.intersect(SkIRect::MakeSize(view_size_)); | 201 clip_area_.intersect(SkIRect::MakeSize(view_size_)); |
| 179 } | 202 } |
| 180 | 203 |
| 181 if (view_changed) { | 204 if (view_changed) { |
| 182 producer_->SetOutputSizeAndClip(view_size_, clip_area_); | 205 producer_->SetOutputSizeAndClip(view_size_, clip_area_); |
| 183 InitiateDrawing(); | 206 InitiateDrawing(); |
| 184 } | 207 } |
| 185 } | 208 } |
| 186 | 209 |
| 187 void PepperView::ApplyBuffer(const SkISize& view_size, | 210 void PepperView::ApplyBuffer(const SkISize& view_size, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 | 371 |
| 349 // If there is a buffer queued for rendering then render it now. | 372 // If there is a buffer queued for rendering then render it now. |
| 350 if (merge_buffer_ != NULL) { | 373 if (merge_buffer_ != NULL) { |
| 351 buffer = merge_buffer_; | 374 buffer = merge_buffer_; |
| 352 merge_buffer_ = NULL; | 375 merge_buffer_ = NULL; |
| 353 FlushBuffer(merge_clip_area_, buffer, merge_region_); | 376 FlushBuffer(merge_clip_area_, buffer, merge_region_); |
| 354 } | 377 } |
| 355 } | 378 } |
| 356 | 379 |
| 357 } // namespace remoting | 380 } // namespace remoting |
| OLD | NEW |