summaryrefslogtreecommitdiffstats
path: root/remoting/client
diff options
context:
space:
mode:
authorhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 20:13:19 +0000
committerhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-14 20:13:19 +0000
commit4cadfe302bd3b36c5d230975a7eeb9bf7382aa11 (patch)
tree79cafe2f3135f87d9eb050f985a0a63c6d7e10d3 /remoting/client
parent2746431e5f3fc89fdc5aa2de2a5df51bc13ad554 (diff)
downloadchromium_src-4cadfe302bd3b36c5d230975a7eeb9bf7382aa11.zip
chromium_src-4cadfe302bd3b36c5d230975a7eeb9bf7382aa11.tar.gz
chromium_src-4cadfe302bd3b36c5d230975a7eeb9bf7382aa11.tar.bz2
Chromoting plugin to use a backing store
Create a backing store for painting image data through the lifetime of the plugin instance. This avoids memory fragmentation of creating small blocks of memory every time it paints. BUG=71885 TEST=None Review URL: http://codereview.chromium.org/6661008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client')
-rw-r--r--remoting/client/plugin/pepper_view.cc38
-rw-r--r--remoting/client/plugin/pepper_view.h3
2 files changed, 26 insertions, 15 deletions
diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc
index 510bde6..7015c9d 100644
--- a/remoting/client/plugin/pepper_view.cc
+++ b/remoting/client/plugin/pepper_view.cc
@@ -8,6 +8,7 @@
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/point.h"
+#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/size.h"
#include "remoting/base/tracer.h"
#include "remoting/base/util.h"
@@ -87,6 +88,12 @@ void PepperView::PaintFrame(media::VideoFrame* frame, UpdatedRects* rects) {
const int kFrameStride = frame->stride(media::VideoFrame::kRGBPlane);
const int kBytesPerPixel = GetBytesPerPixel(media::VideoFrame::RGB32);
+ if (!backing_store_.get() || backing_store_->is_null()) {
+ LOG(ERROR) << "Backing store is not available.";
+ return;
+ }
+
+ // Copy updated regions to the backing store and then paint the regions.
for (size_t i = 0; i < rects->size(); ++i) {
// TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This
// is wrong.
@@ -96,25 +103,21 @@ void PepperView::PaintFrame(media::VideoFrame* frame, UpdatedRects* rects) {
if (r.width() <= 0 || r.height() <= 0)
continue;
- pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(),
- pp::Size(r.width(), r.height()),
- false);
- if (image.is_null()) {
- LOG(ERROR) << "Unable to allocate image of size: "
- << r.width() << "x" << r.height();
- return;
- }
-
- // Copy pixel data into |image|.
uint8* in = frame_data + kFrameStride * r.y() + kBytesPerPixel * r.x();
- uint8* out = reinterpret_cast<uint8*>(image.data());
+ uint8* out = reinterpret_cast<uint8*>(backing_store_->data()) +
+ backing_store_->stride() * r.y() + kBytesPerPixel * r.x();
+
+ // TODO(hclam): We really should eliminate this memory copy.
for (int j = 0; j < r.height(); ++j) {
memcpy(out, in, r.width() * kBytesPerPixel);
in += kFrameStride;
- out += image.stride();
+ out += backing_store_->stride();
}
- graphics2d_.PaintImageData(image, pp::Point(r.x(), r.y()));
+ // Pepper Graphics 2D has a strange and badly documented API that the
+ // point here is the offset from the source rect. Why?
+ graphics2d_.PaintImageData(*backing_store_.get(), pp::Point(0, 0),
+ pp::Rect(r.x(), r.y(), r.width(), r.height()));
}
graphics2d_.Flush(TaskToCompletionCallback(
@@ -192,6 +195,13 @@ void PepperView::SetViewport(int x, int y, int width, int height) {
return;
}
+ // Allocate the backing store to save the desktop image.
+ backing_store_.reset(
+ new pp::ImageData(instance_, pp::ImageData::GetNativeImageDataFormat(),
+ pp::Size(viewport_width_, viewport_height_), false));
+ DCHECK(backing_store_.get() && !backing_store_->is_null())
+ << "Not enough memory for backing store.";
+
instance_->GetScriptableObject()->SetDesktopSize(width, height);
}
@@ -204,8 +214,6 @@ void PepperView::AllocateFrame(media::VideoFrame::Format format,
Task* done) {
DCHECK(CurrentlyOnPluginThread());
- // TODO(ajwong): Implement this to be backed by an pp::ImageData rather than
- // generic memory.
media::VideoFrame::CreateFrame(media::VideoFrame::RGB32,
width, height,
base::TimeDelta(), base::TimeDelta(),
diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h
index 119d1ca..2fb463a 100644
--- a/remoting/client/plugin/pepper_view.h
+++ b/remoting/client/plugin/pepper_view.h
@@ -67,6 +67,9 @@ class PepperView : public ChromotingView,
pp::Graphics2D graphics2d_;
+ // A backing store that saves the current desktop image.
+ scoped_ptr<pp::ImageData> backing_store_;
+
int viewport_width_;
int viewport_height_;