summaryrefslogtreecommitdiffstats
path: root/remoting/base
diff options
context:
space:
mode:
authorgarykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 22:50:00 +0000
committergarykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-06 22:50:00 +0000
commit88552a9c89b99b93211ac5e679a0c13420e294db (patch)
treebe326ad62f7c9c9b3dfdea155a306005af00356a /remoting/base
parentce3b22e8da4fa9ca838423bacd54e45c3030d518 (diff)
downloadchromium_src-88552a9c89b99b93211ac5e679a0c13420e294db.zip
chromium_src-88552a9c89b99b93211ac5e679a0c13420e294db.tar.gz
chromium_src-88552a9c89b99b93211ac5e679a0c13420e294db.tar.bz2
Initial pass at integrating Differ into the chromoting host code.
BUG=none TEST=run Win host; x11 client Review URL: http://codereview.chromium.org/3013015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r--remoting/base/capture_data.h10
-rw-r--r--remoting/base/codec_test.cc10
-rw-r--r--remoting/base/encoder_verbatim.cc13
-rw-r--r--remoting/base/encoder_zlib.cc43
-rw-r--r--remoting/base/encoder_zlib.h11
-rw-r--r--remoting/base/types.h21
6 files changed, 68 insertions, 40 deletions
diff --git a/remoting/base/capture_data.h b/remoting/base/capture_data.h
index 2ac8a12..b06dfa4 100644
--- a/remoting/base/capture_data.h
+++ b/remoting/base/capture_data.h
@@ -9,13 +9,11 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
-#include "gfx/rect.h"
#include "remoting/base/protocol/chromotocol.pb.h"
+#include "remoting/base/types.h"
namespace remoting {
-typedef std::vector<gfx::Rect> RectVector;
-
struct DataPlanes {
static const int kPlaneCount = 3;
uint8* data[kPlaneCount];
@@ -45,7 +43,7 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
// Get the list of updated rectangles in the last capture. The result is
// written into |rects|.
- const RectVector& dirty_rects() const { return dirty_rects_; }
+ const InvalidRects& dirty_rects() const { return dirty_rects_; }
// Get the width of the image captured.
int width() const { return width_; }
@@ -57,11 +55,11 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
PixelFormat pixel_format() const { return pixel_format_; }
// Mutating methods.
- RectVector& mutable_dirty_rects() { return dirty_rects_; }
+ InvalidRects& mutable_dirty_rects() { return dirty_rects_; }
private:
const DataPlanes data_planes_;
- RectVector dirty_rects_;
+ InvalidRects dirty_rects_;
int width_;
int height_;
PixelFormat pixel_format_;
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc
index 4085b28..b0628fb 100644
--- a/remoting/base/codec_test.cc
+++ b/remoting/base/codec_test.cc
@@ -339,8 +339,9 @@ static void TestEncodingRects(Encoder* encoder,
scoped_refptr<CaptureData> data,
const gfx::Rect* rects, int count) {
data->mutable_dirty_rects().clear();
- data->mutable_dirty_rects().insert(
- data->mutable_dirty_rects().begin(), rects, rects + count);
+ for (int i = 0; i < count; ++i) {
+ data->mutable_dirty_rects().insert(rects[i]);
+ }
tester->AddRects(rects, count);
encoder->Encode(data, true,
@@ -371,8 +372,9 @@ static void TestEncodingRects(Encoder* encoder,
scoped_refptr<CaptureData> data,
const gfx::Rect* rects, int count) {
data->mutable_dirty_rects().clear();
- data->mutable_dirty_rects().insert(
- data->mutable_dirty_rects().begin(), rects, rects + count);
+ for (int i = 0; i < count; ++i) {
+ data->mutable_dirty_rects().insert(rects[i]);
+ }
encoder_tester->AddRects(rects, count);
decoder_tester->AddRects(rects, count);
decoder_tester->reset_decode_done();
diff --git a/remoting/base/encoder_verbatim.cc b/remoting/base/encoder_verbatim.cc
index 7f39f27..6a5a7d6 100644
--- a/remoting/base/encoder_verbatim.cc
+++ b/remoting/base/encoder_verbatim.cc
@@ -17,9 +17,12 @@ using media::DataBuffer;
void EncoderVerbatim::Encode(scoped_refptr<CaptureData> capture_data,
bool key_frame,
DataAvailableCallback* data_available_callback) {
- int num_rects = capture_data->dirty_rects().size();
- for (int i = 0; i < num_rects; i++) {
- const gfx::Rect& dirty_rect = capture_data->dirty_rects()[i];
+ const InvalidRects& rects = capture_data->dirty_rects();
+ int num_rects = rects.size();
+ int index = 0;
+ for (InvalidRects::const_iterator r = rects.begin();
+ r != rects.end(); ++r, ++index) {
+ const gfx::Rect& dirty_rect = *r;
HostMessage* msg = new HostMessage();
UpdateStreamPacketMessage* packet = msg->mutable_update_stream_packet();
@@ -29,10 +32,10 @@ void EncoderVerbatim::Encode(scoped_refptr<CaptureData> capture_data,
packet->mutable_end_rect();
EncodingState state = EncodingInProgress;
- if (i == 0) {
+ if (index == 0) {
state |= EncodingStarting;
}
- if (i == num_rects - 1) {
+ if (index == num_rects - 1) {
state |= EncodingEnded;
}
data_available_callback->Run(msg, state);
diff --git a/remoting/base/encoder_zlib.cc b/remoting/base/encoder_zlib.cc
index 848804a..84842ac 100644
--- a/remoting/base/encoder_zlib.cc
+++ b/remoting/base/encoder_zlib.cc
@@ -30,24 +30,25 @@ void EncoderZlib::Encode(scoped_refptr<CaptureData> capture_data,
callback_.reset(data_available_callback);
CompressorZlib compressor;
- for (current_rect_ = 0; current_rect_ < capture_data->dirty_rects().size();
- ++current_rect_) {
- EncodeRect(&compressor);
+ const InvalidRects& rects = capture_data->dirty_rects();
+ int index = 0;
+ for (InvalidRects::const_iterator r = rects.begin();
+ r != rects.end(); ++r, ++index) {
+ EncodeRect(&compressor, *r, index);
}
capture_data_ = NULL;
callback_.reset();
- current_rect_ = 0;
}
-void EncoderZlib::EncodeRect(CompressorZlib* compressor) {
+void EncoderZlib::EncodeRect(CompressorZlib* compressor,
+ const gfx::Rect& rect, size_t rect_index) {
CHECK(capture_data_->data_planes().data[0]);
- const gfx::Rect rect = capture_data_->dirty_rects()[current_rect_];
const int strides = capture_data_->data_planes().strides[0];
const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format());
const int row_size = bytes_per_pixel * rect.width();
- HostMessage* message = PrepareMessage(true);
+ HostMessage* message = PrepareMessage(&rect);
const uint8 * in = capture_data_->data_planes().data[0] +
rect.y() * strides +
rect.x() * bytes_per_pixel;
@@ -61,7 +62,7 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor) {
while (compress_again) {
// Prepare a message for sending out.
if (!message) {
- message = PrepareMessage(false);
+ message = PrepareMessage(NULL);
out = (uint8*)(message->mutable_update_stream_packet()->
mutable_rect_data()->mutable_data()->data());
filled = 0;
@@ -69,10 +70,11 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor) {
Compressor::CompressorFlush flush = Compressor::CompressorNoFlush;
if (row_y == rect.height() - 1) {
- if (current_rect_ == capture_data_->dirty_rects().size() - 1)
+ if (rect_index == capture_data_->dirty_rects().size() - 1) {
flush = Compressor::CompressorFinish;
- else
+ } else {
flush = Compressor::CompressorSyncFlush;
+ }
}
int consumed = 0;
@@ -92,7 +94,7 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor) {
if (filled == packet_size_ || !compress_again) {
message->mutable_update_stream_packet()->mutable_rect_data()->
mutable_data()->resize(filled);
- SubmitMessage(message);
+ SubmitMessage(message, rect_index);
message = NULL;
}
@@ -105,17 +107,16 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor) {
}
}
-HostMessage* EncoderZlib::PrepareMessage(bool new_rect) {
+HostMessage* EncoderZlib::PrepareMessage(const gfx::Rect* rect) {
HostMessage* message = new HostMessage();
UpdateStreamPacketMessage* packet = message->mutable_update_stream_packet();
// Prepare the begin rect content.
- if (new_rect) {
- gfx::Rect rect = capture_data_->dirty_rects()[current_rect_];
- packet->mutable_begin_rect()->set_x(rect.x());
- packet->mutable_begin_rect()->set_y(rect.y());
- packet->mutable_begin_rect()->set_width(rect.width());
- packet->mutable_begin_rect()->set_height(rect.height());
+ if (rect != NULL) {
+ packet->mutable_begin_rect()->set_x(rect->x());
+ packet->mutable_begin_rect()->set_y(rect->y());
+ packet->mutable_begin_rect()->set_width(rect->width());
+ packet->mutable_begin_rect()->set_height(rect->height());
packet->mutable_begin_rect()->set_encoding(EncodingZlib);
packet->mutable_begin_rect()->set_pixel_format(
capture_data_->pixel_format());
@@ -125,11 +126,11 @@ HostMessage* EncoderZlib::PrepareMessage(bool new_rect) {
return message;
}
-void EncoderZlib::SubmitMessage(HostMessage* message) {
+void EncoderZlib::SubmitMessage(HostMessage* message, size_t rect_index) {
EncodingState state = EncodingInProgress;
- if (current_rect_ == 0 && message->update_stream_packet().has_begin_rect())
+ if (rect_index == 0 && message->update_stream_packet().has_begin_rect())
state |= EncodingStarting;
- if (current_rect_ == capture_data_->dirty_rects().size() - 1 &&
+ if (rect_index == capture_data_->dirty_rects().size() - 1 &&
message->update_stream_packet().has_end_rect())
state |= EncodingEnded;
callback_->Run(message, state);
diff --git a/remoting/base/encoder_zlib.h b/remoting/base/encoder_zlib.h
index 9266e2b1..476135b 100644
--- a/remoting/base/encoder_zlib.h
+++ b/remoting/base/encoder_zlib.h
@@ -7,6 +7,8 @@
#include "remoting/base/encoder.h"
+#include "gfx/rect.h"
+
namespace remoting {
class CompressorZlib;
@@ -26,18 +28,19 @@ class EncoderZlib : public Encoder {
private:
// Encode a single dirty rect using compressor.
- void EncodeRect(CompressorZlib* compressor);
+ void EncodeRect(CompressorZlib* compressor, const gfx::Rect& rect,
+ size_t rect_index);
// Create a new HostMessage with the right flag and attributes. The message
// can be used immediately for output of encoding.
- HostMessage* PrepareMessage(bool new_rect);
+ HostMessage* PrepareMessage(const gfx::Rect* rect);
// Submit |message| to |callback_|.
- void SubmitMessage(HostMessage* message);
+ void SubmitMessage(HostMessage* message, size_t rect_index);
scoped_refptr<CaptureData> capture_data_;
scoped_ptr<DataAvailableCallback> callback_;
- size_t current_rect_;
+ //size_t current_rect_;
int packet_size_;
};
diff --git a/remoting/base/types.h b/remoting/base/types.h
new file mode 100644
index 0000000..321bb0a
--- /dev/null
+++ b/remoting/base/types.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_BASE_TYPES_H_
+#define REMOTING_BASE_TYPES_H_
+
+#include <set>
+
+#include "gfx/rect.h"
+
+namespace remoting {
+
+// The collection of 'invalid' screen rectangles.
+// This is used to keep track of regions of the screen that require
+// updating.
+typedef std::set<gfx::Rect> InvalidRects;
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_TYPES_H_