Index: remoting/client/rectangle_update_decoder.cc |
diff --git a/remoting/client/rectangle_update_decoder.cc b/remoting/client/rectangle_update_decoder.cc |
index 3f21a99971b5d0db7365c3cdd00b5f69f2a488ef..379c1ee49561b0bec55712aa5400ee1257e8d198 100644 |
--- a/remoting/client/rectangle_update_decoder.cc |
+++ b/remoting/client/rectangle_update_decoder.cc |
@@ -16,6 +16,7 @@ |
#include "remoting/codec/video_decoder_vp8.h" |
#include "remoting/client/frame_consumer.h" |
#include "remoting/protocol/session_config.h" |
+#include "third_party/libyuv/include/libyuv/convert_argb.h" |
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
using base::Passed; |
@@ -24,6 +25,54 @@ using remoting::protocol::SessionConfig; |
namespace remoting { |
+class RgbToBgrVideoDecoderFilter : public VideoDecoder { |
+ public: |
+ RgbToBgrVideoDecoderFilter(scoped_ptr<VideoDecoder> parent) |
+ : parent_(parent.Pass()) { |
+ } |
+ |
+ virtual void Initialize(const SkISize& screen_size) OVERRIDE { |
+ parent_->Initialize(screen_size); |
+ } |
+ |
+ virtual bool DecodePacket(const VideoPacket& packet) OVERRIDE { |
+ return parent_->DecodePacket(packet); |
+ } |
+ |
+ virtual void Invalidate(const SkISize& view_size, |
+ const SkRegion& region) OVERRIDE { |
+ return parent_->Invalidate(view_size, region); |
+ } |
+ |
+ virtual void RenderFrame(const SkISize& view_size, |
+ const SkIRect& clip_area, |
+ uint8* image_buffer, |
+ int image_stride, |
+ SkRegion* output_region) OVERRIDE { |
+ parent_->RenderFrame(view_size, clip_area, image_buffer, image_stride, |
+ output_region); |
+ |
+ // Byte-swap the pixels for compatibility with the android.graphics.Bitmap |
+ // class. |
+ // TODO(lambroslambrou): Refactor so that the VideoDecoder produces data |
+ // in the right byte-order, instead of swapping it here. |
+ for (SkRegion::Iterator i(*output_region); !i.done(); i.next()) { |
+ SkIRect rect = i.rect(); |
+ uint8* pixels = image_buffer + (rect.top() * image_stride) + |
+ (rect.left() * kBytesPerPixel); |
+ libyuv::ABGRToARGB(pixels, image_stride, pixels, image_stride, |
+ rect.width(), rect.height()); |
+ } |
+ } |
+ |
+ virtual const SkRegion* GetImageShape() OVERRIDE { |
+ return parent_->GetImageShape(); |
+ } |
+ |
+ private: |
+ scoped_ptr<VideoDecoder> parent_; |
+}; |
+ |
RectangleUpdateDecoder::RectangleUpdateDecoder( |
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
@@ -52,6 +101,12 @@ void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { |
} else { |
NOTREACHED() << "Invalid Encoding found: " << codec; |
} |
+ |
+ if (consumer_->GetPixelFormat() == FrameConsumer::FORMAT_RGBA) { |
+ scoped_ptr<VideoDecoder> wrapper( |
+ new RgbToBgrVideoDecoderFilter(decoder_.Pass())); |
+ decoder_ = wrapper.Pass(); |
+ } |
} |
void RectangleUpdateDecoder::DecodePacket(scoped_ptr<VideoPacket> packet, |