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

Side by Side Diff: remoting/base/encoder_row_based.cc

Issue 7491070: Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up shared lib compile Created 9 years, 4 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/base/encoder_row_based.h ('k') | remoting/base/encoder_vp8.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/encoder_row_based.h" 5 #include "remoting/base/encoder_row_based.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "remoting/base/capture_data.h" 8 #include "remoting/base/capture_data.h"
9 #include "remoting/base/compressor_verbatim.h" 9 #include "remoting/base/compressor_verbatim.h"
10 #include "remoting/base/compressor_zlib.h" 10 #include "remoting/base/compressor_zlib.h"
11 #include "remoting/base/util.h" 11 #include "remoting/base/util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 void EncoderRowBased::Encode(scoped_refptr<CaptureData> capture_data, 60 void EncoderRowBased::Encode(scoped_refptr<CaptureData> capture_data,
61 bool key_frame, 61 bool key_frame,
62 DataAvailableCallback* data_available_callback) { 62 DataAvailableCallback* data_available_callback) {
63 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) 63 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32)
64 << "RowBased Encoder only works with RGB32. Got " 64 << "RowBased Encoder only works with RGB32. Got "
65 << capture_data->pixel_format(); 65 << capture_data->pixel_format();
66 capture_data_ = capture_data; 66 capture_data_ = capture_data;
67 callback_.reset(data_available_callback); 67 callback_.reset(data_available_callback);
68 68
69 const InvalidRects& rects = capture_data->dirty_rects(); 69 const SkRegion& region = capture_data->dirty_region();
70 for (InvalidRects::const_iterator r = rects.begin(); r != rects.end(); ++r) { 70 SkRegion::Iterator iter(region);
71 EncodeRect(*r, r == --rects.end()); 71 while (!iter.done()) {
72 SkIRect rect = iter.rect();
73 iter.next();
74 EncodeRect(rect, iter.done());
72 } 75 }
73 76
74 capture_data_ = NULL; 77 capture_data_ = NULL;
75 callback_.reset(); 78 callback_.reset();
76 } 79 }
77 80
78 void EncoderRowBased::EncodeRect(const gfx::Rect& rect, bool last) { 81 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) {
79 CHECK(capture_data_->data_planes().data[0]); 82 CHECK(capture_data_->data_planes().data[0]);
80 const int strides = capture_data_->data_planes().strides[0]; 83 const int strides = capture_data_->data_planes().strides[0];
81 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); 84 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format());
82 const int row_size = bytes_per_pixel * rect.width(); 85 const int row_size = bytes_per_pixel * rect.width();
83 86
84 compressor_->Reset(); 87 compressor_->Reset();
85 88
86 VideoPacket* packet = new VideoPacket(); 89 VideoPacket* packet = new VideoPacket();
87 PrepareUpdateStart(rect, packet); 90 PrepareUpdateStart(rect, packet);
88 const uint8* in = capture_data_->data_planes().data[0] + 91 const uint8* in = capture_data_->data_planes().data[0] +
89 rect.y() * strides + rect.x() * bytes_per_pixel; 92 rect.fTop * strides + rect.fLeft * bytes_per_pixel;
90 // TODO(hclam): Fill in the sequence number. 93 // TODO(hclam): Fill in the sequence number.
91 uint8* out = GetOutputBuffer(packet, packet_size_); 94 uint8* out = GetOutputBuffer(packet, packet_size_);
92 int filled = 0; 95 int filled = 0;
93 int row_pos = 0; // Position in the current row in bytes. 96 int row_pos = 0; // Position in the current row in bytes.
94 int row_y = 0; // Current row. 97 int row_y = 0; // Current row.
95 bool compress_again = true; 98 bool compress_again = true;
96 while (compress_again) { 99 while (compress_again) {
97 // Prepare a message for sending out. 100 // Prepare a message for sending out.
98 if (!packet) { 101 if (!packet) {
99 packet = new VideoPacket(); 102 packet = new VideoPacket();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 138
136 // Reached the end of input row and we're not at the last row. 139 // Reached the end of input row and we're not at the last row.
137 if (row_pos == row_size && row_y < rect.height() - 1) { 140 if (row_pos == row_size && row_y < rect.height() - 1) {
138 row_pos = 0; 141 row_pos = 0;
139 in += strides; 142 in += strides;
140 ++row_y; 143 ++row_y;
141 } 144 }
142 } 145 }
143 } 146 }
144 147
145 void EncoderRowBased::PrepareUpdateStart(const gfx::Rect& rect, 148 void EncoderRowBased::PrepareUpdateStart(const SkIRect& rect,
146 VideoPacket* packet) { 149 VideoPacket* packet) {
147 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); 150 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET);
148 151
149 VideoPacketFormat* format = packet->mutable_format(); 152 VideoPacketFormat* format = packet->mutable_format();
150 format->set_x(rect.x()); 153 format->set_x(rect.fLeft);
151 format->set_y(rect.y()); 154 format->set_y(rect.fTop);
152 format->set_width(rect.width()); 155 format->set_width(rect.width());
153 format->set_height(rect.height()); 156 format->set_height(rect.height());
154 format->set_encoding(encoding_); 157 format->set_encoding(encoding_);
155 if (capture_data_->size() != screen_size_) { 158 if (capture_data_->size() != screen_size_) {
156 screen_size_ = capture_data_->size(); 159 screen_size_ = capture_data_->size();
157 format->set_screen_width(screen_size_.width()); 160 format->set_screen_width(screen_size_.width());
158 format->set_screen_height(screen_size_.height()); 161 format->set_screen_height(screen_size_.height());
159 } 162 }
160 } 163 }
161 164
162 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { 165 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) {
163 packet->mutable_data()->resize(size); 166 packet->mutable_data()->resize(size);
164 // TODO(ajwong): Is there a better way to do this at all??? 167 // TODO(ajwong): Is there a better way to do this at all???
165 return const_cast<uint8*>(reinterpret_cast<const uint8*>( 168 return const_cast<uint8*>(reinterpret_cast<const uint8*>(
166 packet->mutable_data()->data())); 169 packet->mutable_data()->data()));
167 } 170 }
168 171
169 172
170 } // namespace remoting 173 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/encoder_row_based.h ('k') | remoting/base/encoder_vp8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698