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

Side by Side Diff: remoting/client/plugin/pepper_view.cc

Issue 10785041: Make Chromoting client plugin always render at device DPI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase & fix typos. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « remoting/client/plugin/pepper_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/time.h" 11 #include "base/time.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "ppapi/cpp/completion_callback.h" 13 #include "ppapi/cpp/completion_callback.h"
14 #include "ppapi/cpp/graphics_2d.h" 14 #include "ppapi/cpp/dev/graphics_2d_dev.h"
15 #include "ppapi/cpp/dev/view_dev.h"
15 #include "ppapi/cpp/image_data.h" 16 #include "ppapi/cpp/image_data.h"
16 #include "ppapi/cpp/point.h" 17 #include "ppapi/cpp/point.h"
17 #include "ppapi/cpp/rect.h" 18 #include "ppapi/cpp/rect.h"
18 #include "ppapi/cpp/size.h" 19 #include "ppapi/cpp/size.h"
19 #include "remoting/base/util.h" 20 #include "remoting/base/util.h"
20 #include "remoting/client/chromoting_stats.h" 21 #include "remoting/client/chromoting_stats.h"
21 #include "remoting/client/client_context.h" 22 #include "remoting/client/client_context.h"
22 #include "remoting/client/frame_producer.h" 23 #include "remoting/client/frame_producer.h"
23 #include "remoting/client/plugin/chromoting_instance.h" 24 #include "remoting/client/plugin/chromoting_instance.h"
24 #include "remoting/client/plugin/pepper_util.h" 25 #include "remoting/client/plugin/pepper_util.h"
(...skipping 14 matching lines...) Expand all
39 FrameProducer* producer) 40 FrameProducer* producer)
40 : instance_(instance), 41 : instance_(instance),
41 context_(context), 42 context_(context),
42 producer_(producer), 43 producer_(producer),
43 merge_buffer_(NULL), 44 merge_buffer_(NULL),
44 merge_clip_area_(SkIRect::MakeEmpty()), 45 merge_clip_area_(SkIRect::MakeEmpty()),
45 view_size_(SkISize::Make(0, 0)), 46 view_size_(SkISize::Make(0, 0)),
46 clip_area_(SkIRect::MakeEmpty()), 47 clip_area_(SkIRect::MakeEmpty()),
47 source_size_(SkISize::Make(0, 0)), 48 source_size_(SkISize::Make(0, 0)),
48 source_dpi_(SkIPoint::Make(0, 0)), 49 source_dpi_(SkIPoint::Make(0, 0)),
50 view_size_dips_(SkISize::Make(0, 0)),
51 view_scale_(1.0f),
49 flush_pending_(false), 52 flush_pending_(false),
50 frame_received_(false) { 53 frame_received_(false) {
51 InitiateDrawing(); 54 InitiateDrawing();
52 } 55 }
53 56
54 PepperView::~PepperView() { 57 PepperView::~PepperView() {
55 // The producer should now return any pending buffers. At this point, however, 58 // The producer should now return any pending buffers. At this point, however,
56 // ReturnBuffer() tasks scheduled by the producer will not be delivered, 59 // ReturnBuffer() tasks scheduled by the producer will not be delivered,
57 // so we free all the buffers once the producer's queue is empty. 60 // so we free all the buffers once the producer's queue is empty.
58 base::WaitableEvent done_event(true, false); 61 base::WaitableEvent done_event(true, false);
59 producer_->RequestReturnBuffers( 62 producer_->RequestReturnBuffers(
60 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event))); 63 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done_event)));
61 done_event.Wait(); 64 done_event.Wait();
62 65
63 merge_buffer_ = NULL; 66 merge_buffer_ = NULL;
64 while (!buffers_.empty()) { 67 while (!buffers_.empty()) {
65 FreeBuffer(buffers_.front()); 68 FreeBuffer(buffers_.front());
66 } 69 }
67 } 70 }
68 71
69 void PepperView::SetView(const SkISize& view_size, const SkIRect& clip_area) { 72 void PepperView::SetView(const pp::View& view) {
70 bool view_changed = false; 73 bool view_changed = false;
71 74
72 if (view_size_ != view_size) { 75 pp::Rect pp_size = view.GetRect();
76 SkISize new_size_dips = SkISize::Make(pp_size.width(), pp_size.height());
77 pp::ViewDev view_dev(view);
78 float new_scale = view_dev.GetDeviceScale();
79
80 if (view_size_dips_ != new_size_dips || view_scale_ != new_scale) {
73 view_changed = true; 81 view_changed = true;
74 view_size_ = view_size; 82 view_scale_ = new_scale;
83 view_size_dips_ = new_size_dips;
84 view_size_ = SkISize::Make(ceilf(view_size_dips_.width() * view_scale_),
85 ceilf(view_size_dips_.height() * view_scale_));
75 86
76 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height()); 87 pp::Size pp_size = pp::Size(view_size_.width(), view_size_.height());
77 graphics2d_ = pp::Graphics2D(instance_, pp_size, true); 88 graphics2d_ = pp::Graphics2D(instance_, pp_size, true);
89
90 // Ideally we would always let Graphics2D scale us, but the output quality
91 // is lousy, so we don't.
92 pp::Graphics2DDev graphics2d_dev(graphics2d_);
93 graphics2d_dev.SetScale(1.0f / view_scale_);
94
78 bool result = instance_->BindGraphics(graphics2d_); 95 bool result = instance_->BindGraphics(graphics2d_);
79 96
80 // There is no good way to handle this error currently. 97 // There is no good way to handle this error currently.
81 DCHECK(result) << "Couldn't bind the device context."; 98 DCHECK(result) << "Couldn't bind the device context.";
82 } 99 }
83 100
84 if (clip_area_ != clip_area) { 101 pp::Rect pp_clip = view.GetClipRect();
102 SkIRect new_clip = SkIRect::MakeLTRB(floorf(pp_clip.x() * view_scale_),
103 floorf(pp_clip.y() * view_scale_),
104 ceilf(pp_clip.right() * view_scale_),
105 ceilf(pp_clip.bottom() * view_scale_));
106 if (clip_area_ != new_clip) {
85 view_changed = true; 107 view_changed = true;
86 108
87 // YUV to RGB conversion may require even X and Y coordinates for 109 // YUV to RGB conversion may require even X and Y coordinates for
88 // the top left corner of the clipping area. 110 // the top left corner of the clipping area.
89 clip_area_ = AlignRect(clip_area); 111 clip_area_ = AlignRect(new_clip);
90 clip_area_.intersect(SkIRect::MakeSize(view_size_)); 112 clip_area_.intersect(SkIRect::MakeSize(view_size_));
91 } 113 }
92 114
93 if (view_changed) { 115 if (view_changed) {
94 producer_->SetOutputSizeAndClip(view_size_, clip_area_); 116 producer_->SetOutputSizeAndClip(view_size_, clip_area_);
95 InitiateDrawing(); 117 InitiateDrawing();
96 } 118 }
97 } 119 }
98 120
99 void PepperView::ApplyBuffer(const SkISize& view_size, 121 void PepperView::ApplyBuffer(const SkISize& view_size,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 275
254 // If there is a buffer queued for rendering then render it now. 276 // If there is a buffer queued for rendering then render it now.
255 if (merge_buffer_ != NULL) { 277 if (merge_buffer_ != NULL) {
256 buffer = merge_buffer_; 278 buffer = merge_buffer_;
257 merge_buffer_ = NULL; 279 merge_buffer_ = NULL;
258 FlushBuffer(merge_clip_area_, buffer, merge_region_); 280 FlushBuffer(merge_clip_area_, buffer, merge_region_);
259 } 281 }
260 } 282 }
261 283
262 } // namespace remoting 284 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/pepper_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698