| OLD | NEW |
| 1 // Copyright (c) 2011 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/client/plugin/pepper_view.h" | 5 #include "remoting/client/plugin/pepper_view.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" |
| 8 #include "ppapi/cpp/graphics_2d.h" | 9 #include "ppapi/cpp/graphics_2d.h" |
| 9 #include "ppapi/cpp/image_data.h" | 10 #include "ppapi/cpp/image_data.h" |
| 10 #include "ppapi/cpp/point.h" | 11 #include "ppapi/cpp/point.h" |
| 11 #include "ppapi/cpp/size.h" | 12 #include "ppapi/cpp/size.h" |
| 12 #include "remoting/base/tracer.h" | 13 #include "remoting/base/tracer.h" |
| 13 #include "remoting/base/util.h" | 14 #include "remoting/base/util.h" |
| 14 #include "remoting/client/client_context.h" | 15 #include "remoting/client/client_context.h" |
| 15 #include "remoting/client/plugin/chromoting_instance.h" | 16 #include "remoting/client/plugin/chromoting_instance.h" |
| 16 #include "remoting/client/plugin/pepper_util.h" | 17 #include "remoting/client/plugin/pepper_util.h" |
| 17 | 18 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 40 task_factory_.RevokeAll(); | 41 task_factory_.RevokeAll(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void PepperView::Paint() { | 44 void PepperView::Paint() { |
| 44 DCHECK(instance_->CurrentlyOnPluginThread()); | 45 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 45 | 46 |
| 46 TraceContext::tracer()->PrintString("Start Paint."); | 47 TraceContext::tracer()->PrintString("Start Paint."); |
| 47 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This | 48 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This |
| 48 // is wrong. | 49 // is wrong. |
| 49 if (is_static_fill_) { | 50 if (is_static_fill_) { |
| 50 LOG(ERROR) << "Static filling " << static_fill_color_; | 51 instance_->LogDebugError( |
| 52 StringPrintf("Static filling %08x", static_fill_color_)); |
| 51 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), | 53 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), |
| 52 pp::Size(viewport_width_, viewport_height_), | 54 pp::Size(viewport_width_, viewport_height_), |
| 53 false); | 55 false); |
| 54 if (image.is_null()) { | 56 if (image.is_null()) { |
| 55 LOG(ERROR) << "Unable to allocate image of size: " | 57 instance_->LogDebugError( |
| 56 << viewport_width_ << "x" << viewport_height_; | 58 StringPrintf("Unable to allocate image of size: %dx%d", |
| 59 viewport_width_, viewport_height_)); |
| 57 return; | 60 return; |
| 58 } | 61 } |
| 59 | 62 |
| 60 for (int y = 0; y < image.size().height(); y++) { | 63 for (int y = 0; y < image.size().height(); y++) { |
| 61 for (int x = 0; x < image.size().width(); x++) { | 64 for (int x = 0; x < image.size().width(); x++) { |
| 62 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; | 65 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; |
| 63 } | 66 } |
| 64 } | 67 } |
| 65 | 68 |
| 66 // For ReplaceContents, make sure the image size matches the device context | 69 // For ReplaceContents, make sure the image size matches the device context |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 const gfx::Rect& r = (*rects)[i]; | 96 const gfx::Rect& r = (*rects)[i]; |
| 94 | 97 |
| 95 // TODO(hclam): Make sure rectangles are valid. | 98 // TODO(hclam): Make sure rectangles are valid. |
| 96 if (r.width() <= 0 || r.height() <= 0) | 99 if (r.width() <= 0 || r.height() <= 0) |
| 97 continue; | 100 continue; |
| 98 | 101 |
| 99 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), | 102 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), |
| 100 pp::Size(r.width(), r.height()), | 103 pp::Size(r.width(), r.height()), |
| 101 false); | 104 false); |
| 102 if (image.is_null()) { | 105 if (image.is_null()) { |
| 103 LOG(ERROR) << "Unable to allocate image of size: " | 106 instance_->LogDebugError( |
| 104 << r.width() << "x" << r.height(); | 107 StringPrintf("Unable to allocate image of size: %dx%d", |
| 108 r.width(), r.height())); |
| 105 return; | 109 return; |
| 106 } | 110 } |
| 107 | 111 |
| 108 // Copy pixel data into |image|. | 112 // Copy pixel data into |image|. |
| 109 uint8* in = frame_data + kFrameStride * r.y() + kBytesPerPixel * r.x(); | 113 uint8* in = frame_data + kFrameStride * r.y() + kBytesPerPixel * r.x(); |
| 110 uint8* out = reinterpret_cast<uint8*>(image.data()); | 114 uint8* out = reinterpret_cast<uint8*>(image.data()); |
| 111 for (int j = 0; j < r.height(); ++j) { | 115 for (int j = 0; j < r.height(); ++j) { |
| 112 memcpy(out, in, r.width() * kBytesPerPixel); | 116 memcpy(out, in, r.width() * kBytesPerPixel); |
| 113 in += kFrameStride; | 117 in += kFrameStride; |
| 114 out += image.stride(); | 118 out += image.stride(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if ((width == viewport_width_) && (height == viewport_height_)) | 185 if ((width == viewport_width_) && (height == viewport_height_)) |
| 182 return; | 186 return; |
| 183 | 187 |
| 184 viewport_width_ = width; | 188 viewport_width_ = width; |
| 185 viewport_height_ = height; | 189 viewport_height_ = height; |
| 186 | 190 |
| 187 graphics2d_ = pp::Graphics2D(instance_, | 191 graphics2d_ = pp::Graphics2D(instance_, |
| 188 pp::Size(viewport_width_, viewport_height_), | 192 pp::Size(viewport_width_, viewport_height_), |
| 189 false); | 193 false); |
| 190 if (!instance_->BindGraphics(graphics2d_)) { | 194 if (!instance_->BindGraphics(graphics2d_)) { |
| 191 LOG(ERROR) << "Couldn't bind the device context."; | 195 instance_->LogDebugError("Couldn't bind the device context."); |
| 192 return; | 196 return; |
| 193 } | 197 } |
| 194 | 198 |
| 195 instance_->GetScriptableObject()->SetDesktopSize(width, height); | 199 instance_->GetScriptableObject()->SetDesktopSize(width, height); |
| 196 } | 200 } |
| 197 | 201 |
| 198 void PepperView::AllocateFrame(media::VideoFrame::Format format, | 202 void PepperView::AllocateFrame(media::VideoFrame::Format format, |
| 199 size_t width, | 203 size_t width, |
| 200 size_t height, | 204 size_t height, |
| 201 base::TimeDelta timestamp, | 205 base::TimeDelta timestamp, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 214 (*frame_out)->AddRef(); | 218 (*frame_out)->AddRef(); |
| 215 } | 219 } |
| 216 done->Run(); | 220 done->Run(); |
| 217 delete done; | 221 delete done; |
| 218 } | 222 } |
| 219 | 223 |
| 220 void PepperView::ReleaseFrame(media::VideoFrame* frame) { | 224 void PepperView::ReleaseFrame(media::VideoFrame* frame) { |
| 221 DCHECK(instance_->CurrentlyOnPluginThread()); | 225 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 222 | 226 |
| 223 if (frame) { | 227 if (frame) { |
| 224 LOG(WARNING) << "Frame released."; | 228 instance_->LogDebugError("Frame released."); |
| 225 frame->Release(); | 229 frame->Release(); |
| 226 } | 230 } |
| 227 } | 231 } |
| 228 | 232 |
| 229 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, | 233 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, |
| 230 UpdatedRects* rects, | 234 UpdatedRects* rects, |
| 231 Task* done) { | 235 Task* done) { |
| 232 DCHECK(instance_->CurrentlyOnPluginThread()); | 236 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 233 | 237 |
| 234 TraceContext::tracer()->PrintString("Calling PaintFrame"); | 238 TraceContext::tracer()->PrintString("Calling PaintFrame"); |
| 235 // TODO(ajwong): Clean up this API to be async so we don't need to use a | 239 // TODO(ajwong): Clean up this API to be async so we don't need to use a |
| 236 // member variable as a hack. | 240 // member variable as a hack. |
| 237 PaintFrame(frame, rects); | 241 PaintFrame(frame, rects); |
| 238 done->Run(); | 242 done->Run(); |
| 239 delete done; | 243 delete done; |
| 240 } | 244 } |
| 241 | 245 |
| 242 void PepperView::OnPaintDone() { | 246 void PepperView::OnPaintDone() { |
| 243 DCHECK(instance_->CurrentlyOnPluginThread()); | 247 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 244 | 248 |
| 245 // TODO(ajwong):Probably should set some variable to allow repaints to | 249 // TODO(ajwong):Probably should set some variable to allow repaints to |
| 246 // actually paint. | 250 // actually paint. |
| 247 TraceContext::tracer()->PrintString("Paint flushed"); | 251 TraceContext::tracer()->PrintString("Paint flushed"); |
| 248 return; | 252 return; |
| 249 } | 253 } |
| 250 | 254 |
| 251 } // namespace remoting | 255 } // namespace remoting |
| OLD | NEW |