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

Side by Side Diff: remoting/host/video_frame_capturer_mac.mm

Issue 10824035: Send correct DPI to client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | 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/host/video_frame_capturer.h" 5 #include "remoting/host/video_frame_capturer.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <Cocoa/Cocoa.h> 8 #include <Cocoa/Cocoa.h>
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <IOKit/pwr_mgt/IOPMLib.h> 10 #include <IOKit/pwr_mgt/IOPMLib.h>
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 cgl_context_ = NULL; 111 cgl_context_ = NULL;
112 pixel_buffer_object_ = 0; 112 pixel_buffer_object_ = 0;
113 } 113 }
114 } 114 }
115 115
116 // A class representing a full-frame pixel buffer. 116 // A class representing a full-frame pixel buffer.
117 class VideoFrameBuffer { 117 class VideoFrameBuffer {
118 public: 118 public:
119 VideoFrameBuffer() : 119 VideoFrameBuffer() :
120 size_(SkISize::Make(0, 0)), 120 size_(SkISize::Make(0, 0)),
121 dpi_(SkIPoint::Make(0, 0)),
121 bytes_per_row_(0), 122 bytes_per_row_(0),
122 needs_update_(true) { 123 needs_update_(true) {
123 } 124 }
124 125
125 // If the buffer is marked as needing to be updated (for example after the 126 // If the buffer is marked as needing to be updated (for example after the
126 // screen mode changes) and is the wrong size, then release the old buffer 127 // screen mode changes) and is the wrong size, then release the old buffer
127 // and create a new one. 128 // and create a new one.
128 void Update() { 129 void Update() {
129 if (needs_update_) { 130 if (needs_update_) {
130 needs_update_ = false; 131 needs_update_ = false;
131 CGDirectDisplayID mainDevice = CGMainDisplayID(); 132 CGDirectDisplayID mainDevice = CGMainDisplayID();
132 int width = CGDisplayPixelsWide(mainDevice); 133 int width = CGDisplayPixelsWide(mainDevice);
133 int height = CGDisplayPixelsHigh(mainDevice); 134 int height = CGDisplayPixelsHigh(mainDevice);
Jamie 2012/07/26 00:57:17 We could get width and height from deviceDescripti
Lambros 2012/07/26 01:21:59 Well, I suppose you could use CGDisplayScreenSize(
134 if (width != size_.width() || height != size_.height()) { 135 if (width != size_.width() || height != size_.height()) {
135 size_.set(width, height); 136 size_.set(width, height);
136 bytes_per_row_ = width * sizeof(uint32_t); 137 bytes_per_row_ = width * sizeof(uint32_t);
137 size_t buffer_size = width * height * sizeof(uint32_t); 138 size_t buffer_size = width * height * sizeof(uint32_t);
138 ptr_.reset(new uint8[buffer_size]); 139 ptr_.reset(new uint8[buffer_size]);
139 } 140 }
141 NSScreen* screen = [NSScreen mainScreen];
142 NSDictionary* attr = [screen deviceDescription];
143 NSSize resolution = [[attr objectForKey: NSDeviceResolution] sizeValue];
Lambros 2012/07/26 01:21:59 nit: no space after colon
144 dpi_.set(resolution.width, resolution.height);
140 } 145 }
141 } 146 }
142 147
143 SkISize size() const { return size_; } 148 SkISize size() const { return size_; }
149 SkIPoint dpi() const { return dpi_; }
144 int bytes_per_row() const { return bytes_per_row_; } 150 int bytes_per_row() const { return bytes_per_row_; }
145 uint8* ptr() const { return ptr_.get(); } 151 uint8* ptr() const { return ptr_.get(); }
146 152
147 void set_needs_update() { needs_update_ = true; } 153 void set_needs_update() { needs_update_ = true; }
148 154
149 private: 155 private:
150 SkISize size_; 156 SkISize size_;
157 SkIPoint dpi_;
151 int bytes_per_row_; 158 int bytes_per_row_;
152 scoped_array<uint8> ptr_; 159 scoped_array<uint8> ptr_;
153 bool needs_update_; 160 bool needs_update_;
154 161
155 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); 162 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer);
156 }; 163 };
157 164
158 // A class to perform video frame capturing for mac. 165 // A class to perform video frame capturing for mac.
159 class VideoFrameCapturerMac : public VideoFrameCapturer { 166 class VideoFrameCapturerMac : public VideoFrameCapturer {
160 public: 167 public:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 DataPlanes planes; 392 DataPlanes planes;
386 planes.data[0] = current_buffer.ptr(); 393 planes.data[0] = current_buffer.ptr();
387 planes.strides[0] = current_buffer.bytes_per_row(); 394 planes.strides[0] = current_buffer.bytes_per_row();
388 if (flip) { 395 if (flip) {
389 planes.strides[0] = -planes.strides[0]; 396 planes.strides[0] = -planes.strides[0];
390 planes.data[0] += 397 planes.data[0] +=
391 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row(); 398 (current_buffer.size().height() - 1) * current_buffer.bytes_per_row();
392 } 399 }
393 400
394 data = new CaptureData(planes, current_buffer.size(), pixel_format()); 401 data = new CaptureData(planes, current_buffer.size(), pixel_format());
402 data->set_dpi(current_buffer.dpi());
395 data->mutable_dirty_region() = region; 403 data->mutable_dirty_region() = region;
396 404
397 current_buffer_ = (current_buffer_ + 1) % kNumBuffers; 405 current_buffer_ = (current_buffer_ + 1) % kNumBuffers;
398 helper_.set_size_most_recent(data->size()); 406 helper_.set_size_most_recent(data->size());
399 display_configuration_capture_event_.Signal(); 407 display_configuration_capture_event_.Signal();
400 408
401 CaptureCursor(); 409 CaptureCursor();
402 410
403 callback.Run(data); 411 callback.Run(data);
404 } 412 }
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 VideoFrameCapturer* VideoFrameCapturer::Create() { 774 VideoFrameCapturer* VideoFrameCapturer::Create() {
767 VideoFrameCapturerMac* capturer = new VideoFrameCapturerMac(); 775 VideoFrameCapturerMac* capturer = new VideoFrameCapturerMac();
768 if (!capturer->Init()) { 776 if (!capturer->Init()) {
769 delete capturer; 777 delete capturer;
770 capturer = NULL; 778 capturer = NULL;
771 } 779 }
772 return capturer; 780 return capturer;
773 } 781 }
774 782
775 } // namespace remoting 783 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698