Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ppapi/cpp/graphics_2d.h" | 8 #include "ppapi/cpp/graphics_2d.h" |
| 9 #include "ppapi/cpp/image_data.h" | 9 #include "ppapi/cpp/image_data.h" |
| 10 #include "ppapi/cpp/point.h" | 10 #include "ppapi/cpp/point.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 } | 28 } |
| 29 | 29 |
| 30 PepperView::~PepperView() { | 30 PepperView::~PepperView() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 bool PepperView::Initialize() { | 33 bool PepperView::Initialize() { |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void PepperView::TearDown() { | 37 void PepperView::TearDown() { |
| 38 DCHECK(instance_->CurrentlyOnPluginThread()); | |
| 38 } | 39 } |
| 39 | 40 |
| 40 void PepperView::Paint() { | 41 void PepperView::Paint() { |
| 41 if (!instance_->CurrentlyOnPluginThread()) { | 42 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 42 RunTaskOnPluginThread(NewTracedMethod(this, &PepperView::Paint)); | |
| 43 return; | |
| 44 } | |
| 45 | 43 |
| 46 TraceContext::tracer()->PrintString("Start Paint."); | 44 TraceContext::tracer()->PrintString("Start Paint."); |
| 47 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This | 45 // TODO(ajwong): We're assuming the native format is BGRA_PREMUL below. This |
| 48 // is wrong. | 46 // is wrong. |
| 49 if (is_static_fill_) { | 47 if (is_static_fill_) { |
| 50 LOG(ERROR) << "Static filling " << static_fill_color_; | 48 LOG(ERROR) << "Static filling " << static_fill_color_; |
| 51 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), | 49 pp::ImageData image(instance_, pp::ImageData::GetNativeImageDataFormat(), |
| 52 pp::Size(viewport_width_, viewport_height_), | 50 pp::Size(viewport_width_, viewport_height_), |
| 53 false); | 51 false); |
| 54 if (image.is_null()) { | 52 if (image.is_null()) { |
| 55 LOG(ERROR) << "Unable to allocate image of size: " | 53 LOG(ERROR) << "Unable to allocate image of size: " |
| 56 << viewport_width_ << "x" << viewport_height_; | 54 << viewport_width_ << "x" << viewport_height_; |
| 57 return; | 55 return; |
| 58 } | 56 } |
| 59 | 57 |
| 60 for (int y = 0; y < image.size().height(); y++) { | 58 for (int y = 0; y < image.size().height(); y++) { |
| 61 for (int x = 0; x < image.size().width(); x++) { | 59 for (int x = 0; x < image.size().width(); x++) { |
| 62 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; | 60 *image.GetAddr32(pp::Point(x, y)) = static_fill_color_; |
| 63 } | 61 } |
| 64 } | 62 } |
| 65 | 63 |
| 66 // For ReplaceContents, make sure the image size matches the device context | 64 // For ReplaceContents, make sure the image size matches the device context |
| 67 // size! Otherwise, this will just silently do nothing. | 65 // size! Otherwise, this will just silently do nothing. |
| 68 graphics2d_.ReplaceContents(&image); | 66 graphics2d_.ReplaceContents(&image); |
| 69 graphics2d_.Flush(TaskToCompletionCallback( | 67 graphics2d_.Flush(TaskToCompletionCallback( |
| 70 NewTracedMethod(this, &PepperView::OnPaintDone))); | 68 NewTracedMethod(this, &PepperView::OnPaintDone))); |
|
Sergey Ulanov
2011/01/25 21:29:37
Do we have any guarantees that this task is not ca
Alpha Left Google
2011/01/25 22:20:47
Done.
| |
| 71 } else { | 69 } else { |
| 72 // TODO(ajwong): We need to keep a backing store image of the viewport that | 70 // TODO(ajwong): We need to keep a backing store image of the viewport that |
| 73 // has the data here which can be redrawn. | 71 // has the data here which can be redrawn. |
| 74 return; | 72 return; |
| 75 } | 73 } |
| 76 TraceContext::tracer()->PrintString("End Paint."); | 74 TraceContext::tracer()->PrintString("End Paint."); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void PepperView::PaintFrame(media::VideoFrame* frame, UpdatedRects* rects) { | 77 void PepperView::PaintFrame(media::VideoFrame* frame, UpdatedRects* rects) { |
| 80 DCHECK(instance_->CurrentlyOnPluginThread()); | 78 DCHECK(instance_->CurrentlyOnPluginThread()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 102 // Force alpha to be set to 255. | 100 // Force alpha to be set to 255. |
| 103 *image.GetAddr32(pp::Point(x, y)) = | 101 *image.GetAddr32(pp::Point(x, y)) = |
| 104 frame_data[y*frame_width + x] | 0xFF000000; | 102 frame_data[y*frame_width + x] | 0xFF000000; |
| 105 } | 103 } |
| 106 } | 104 } |
| 107 | 105 |
| 108 // For ReplaceContents, make sure the image size matches the device context | 106 // For ReplaceContents, make sure the image size matches the device context |
| 109 // size! Otherwise, this will just silently do nothing. | 107 // size! Otherwise, this will just silently do nothing. |
| 110 graphics2d_.ReplaceContents(&image); | 108 graphics2d_.ReplaceContents(&image); |
| 111 graphics2d_.Flush(TaskToCompletionCallback( | 109 graphics2d_.Flush(TaskToCompletionCallback( |
| 112 NewTracedMethod(this, &PepperView::OnPaintDone))); | 110 NewTracedMethod(this, &PepperView::OnPaintDone))); |
|
Sergey Ulanov
2011/01/25 21:29:37
same here
Alpha Left Google
2011/01/25 22:20:47
Done.
| |
| 113 | 111 |
| 114 TraceContext::tracer()->PrintString("End Paint Frame."); | 112 TraceContext::tracer()->PrintString("End Paint Frame."); |
| 115 } | 113 } |
| 116 | 114 |
| 117 void PepperView::SetSolidFill(uint32 color) { | 115 void PepperView::SetSolidFill(uint32 color) { |
| 118 if (!instance_->CurrentlyOnPluginThread()) { | 116 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 119 RunTaskOnPluginThread( | |
| 120 NewTracedMethod(this, &PepperView::SetSolidFill, color)); | |
| 121 return; | |
| 122 } | |
| 123 | 117 |
| 124 is_static_fill_ = true; | 118 is_static_fill_ = true; |
| 125 static_fill_color_ = color; | 119 static_fill_color_ = color; |
| 126 } | 120 } |
| 127 | 121 |
| 128 void PepperView::UnsetSolidFill() { | 122 void PepperView::UnsetSolidFill() { |
| 129 if (!instance_->CurrentlyOnPluginThread()) { | 123 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 130 RunTaskOnPluginThread( | |
| 131 NewTracedMethod(this, &PepperView::UnsetSolidFill)); | |
| 132 return; | |
| 133 } | |
| 134 | 124 |
| 135 is_static_fill_ = false; | 125 is_static_fill_ = false; |
| 136 } | 126 } |
| 137 | 127 |
| 138 void PepperView::SetConnectionState(ConnectionState state) { | 128 void PepperView::SetConnectionState(ConnectionState state) { |
| 139 if (!instance_->CurrentlyOnPluginThread()) { | 129 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 140 RunTaskOnPluginThread( | |
| 141 NewRunnableMethod(this, &PepperView::SetConnectionState, state)); | |
| 142 return; | |
| 143 } | |
| 144 | 130 |
| 145 ChromotingScriptableObject* scriptable_obj = instance_->GetScriptableObject(); | 131 ChromotingScriptableObject* scriptable_obj = instance_->GetScriptableObject(); |
| 146 switch (state) { | 132 switch (state) { |
| 147 case CREATED: | 133 case CREATED: |
| 148 SetSolidFill(kCreatedColor); | 134 SetSolidFill(kCreatedColor); |
| 149 scriptable_obj->SetConnectionInfo(STATUS_CONNECTING, QUALITY_UNKNOWN); | 135 scriptable_obj->SetConnectionInfo(STATUS_CONNECTING, QUALITY_UNKNOWN); |
| 150 break; | 136 break; |
| 151 | 137 |
| 152 case CONNECTED: | 138 case CONNECTED: |
| 153 UnsetSolidFill(); | 139 UnsetSolidFill(); |
| 154 scriptable_obj->SetConnectionInfo(STATUS_CONNECTED, QUALITY_UNKNOWN); | 140 scriptable_obj->SetConnectionInfo(STATUS_CONNECTED, QUALITY_UNKNOWN); |
| 155 break; | 141 break; |
| 156 | 142 |
| 157 case DISCONNECTED: | 143 case DISCONNECTED: |
| 158 SetSolidFill(kDisconnectedColor); | 144 SetSolidFill(kDisconnectedColor); |
| 159 scriptable_obj->SetConnectionInfo(STATUS_CLOSED, QUALITY_UNKNOWN); | 145 scriptable_obj->SetConnectionInfo(STATUS_CLOSED, QUALITY_UNKNOWN); |
| 160 break; | 146 break; |
| 161 | 147 |
| 162 case FAILED: | 148 case FAILED: |
| 163 SetSolidFill(kFailedColor); | 149 SetSolidFill(kFailedColor); |
| 164 scriptable_obj->SetConnectionInfo(STATUS_FAILED, QUALITY_UNKNOWN); | 150 scriptable_obj->SetConnectionInfo(STATUS_FAILED, QUALITY_UNKNOWN); |
| 165 break; | 151 break; |
| 166 } | 152 } |
| 167 } | 153 } |
| 168 | 154 |
| 169 void PepperView::SetViewport(int x, int y, int width, int height) { | 155 void PepperView::SetViewport(int x, int y, int width, int height) { |
| 170 if (!instance_->CurrentlyOnPluginThread()) { | 156 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 171 RunTaskOnPluginThread(NewTracedMethod(this, &PepperView::SetViewport, | |
| 172 x, y, width, height)); | |
| 173 return; | |
| 174 } | |
| 175 | 157 |
| 176 // TODO(ajwong): Should we ignore x & y updates? What do those even mean? | 158 // TODO(ajwong): Should we ignore x & y updates? What do those even mean? |
| 177 | 159 |
| 178 // TODO(ajwong): What does viewport x, y mean to a plugin anyways? | 160 // TODO(ajwong): What does viewport x, y mean to a plugin anyways? |
| 179 viewport_x_ = x; | 161 viewport_x_ = x; |
| 180 viewport_y_ = y; | 162 viewport_y_ = y; |
| 181 viewport_width_ = width; | 163 viewport_width_ = width; |
| 182 viewport_height_ = height; | 164 viewport_height_ = height; |
| 183 | 165 |
| 184 graphics2d_ = pp::Graphics2D(instance_, | 166 graphics2d_ = pp::Graphics2D(instance_, |
| 185 pp::Size(viewport_width_, viewport_height_), | 167 pp::Size(viewport_width_, viewport_height_), |
| 186 false); | 168 false); |
| 187 if (!instance_->BindGraphics(graphics2d_)) { | 169 if (!instance_->BindGraphics(graphics2d_)) { |
| 188 LOG(ERROR) << "Couldn't bind the device context."; | 170 LOG(ERROR) << "Couldn't bind the device context."; |
| 189 return; | 171 return; |
| 190 } | 172 } |
| 191 } | 173 } |
| 192 | 174 |
| 193 void PepperView::AllocateFrame(media::VideoFrame::Format format, | 175 void PepperView::AllocateFrame(media::VideoFrame::Format format, |
| 194 size_t width, | 176 size_t width, |
| 195 size_t height, | 177 size_t height, |
| 196 base::TimeDelta timestamp, | 178 base::TimeDelta timestamp, |
| 197 base::TimeDelta duration, | 179 base::TimeDelta duration, |
| 198 scoped_refptr<media::VideoFrame>* frame_out, | 180 scoped_refptr<media::VideoFrame>* frame_out, |
| 199 Task* done) { | 181 Task* done) { |
| 182 DCHECK(instance_->CurrentlyOnPluginThread()); | |
| 183 | |
| 200 // TODO(ajwong): Implement this to be backed by an pp::ImageData rather than | 184 // TODO(ajwong): Implement this to be backed by an pp::ImageData rather than |
| 201 // generic memory. | 185 // generic memory. |
| 202 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, | 186 media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, |
| 203 width, height, | 187 width, height, |
| 204 base::TimeDelta(), base::TimeDelta(), | 188 base::TimeDelta(), base::TimeDelta(), |
| 205 frame_out); | 189 frame_out); |
| 206 if (*frame_out) { | 190 if (*frame_out) { |
| 207 (*frame_out)->AddRef(); | 191 (*frame_out)->AddRef(); |
| 208 } | 192 } |
| 209 done->Run(); | 193 done->Run(); |
| 210 delete done; | 194 delete done; |
| 211 } | 195 } |
| 212 | 196 |
| 213 void PepperView::ReleaseFrame(media::VideoFrame* frame) { | 197 void PepperView::ReleaseFrame(media::VideoFrame* frame) { |
| 198 DCHECK(instance_->CurrentlyOnPluginThread()); | |
| 199 | |
| 214 if (frame) { | 200 if (frame) { |
| 215 LOG(WARNING) << "Frame released."; | 201 LOG(WARNING) << "Frame released."; |
| 216 frame->Release(); | 202 frame->Release(); |
| 217 } | 203 } |
| 218 } | 204 } |
| 219 | 205 |
| 220 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, | 206 void PepperView::OnPartialFrameOutput(media::VideoFrame* frame, |
| 221 UpdatedRects* rects, | 207 UpdatedRects* rects, |
| 222 Task* done) { | 208 Task* done) { |
| 223 if (!instance_->CurrentlyOnPluginThread()) { | 209 DCHECK(instance_->CurrentlyOnPluginThread()); |
| 224 RunTaskOnPluginThread( | |
| 225 NewTracedMethod(this, &PepperView::OnPartialFrameOutput, | |
| 226 make_scoped_refptr(frame), rects, done)); | |
| 227 return; | |
| 228 } | |
| 229 | 210 |
| 230 TraceContext::tracer()->PrintString("Calling PaintFrame"); | 211 TraceContext::tracer()->PrintString("Calling PaintFrame"); |
| 231 // TODO(ajwong): Clean up this API to be async so we don't need to use a | 212 // TODO(ajwong): Clean up this API to be async so we don't need to use a |
| 232 // member variable as a hack. | 213 // member variable as a hack. |
| 233 PaintFrame(frame, rects); | 214 PaintFrame(frame, rects); |
| 234 done->Run(); | 215 done->Run(); |
| 235 delete done; | 216 delete done; |
| 236 } | 217 } |
| 237 | 218 |
| 238 void PepperView::OnPaintDone() { | 219 void PepperView::OnPaintDone() { |
| 220 DCHECK(instance_->CurrentlyOnPluginThread()); | |
| 221 | |
| 239 // TODO(ajwong):Probably should set some variable to allow repaints to | 222 // TODO(ajwong):Probably should set some variable to allow repaints to |
| 240 // actually paint. | 223 // actually paint. |
| 241 TraceContext::tracer()->PrintString("Paint flushed"); | 224 TraceContext::tracer()->PrintString("Paint flushed"); |
| 242 return; | 225 return; |
| 243 } | 226 } |
| 244 | 227 |
| 245 } // namespace remoting | 228 } // namespace remoting |
| OLD | NEW |