| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This class is an implementation of the ChromotingView for Pepper. It is | 5 // This class is an implementation of the ChromotingView for Pepper. It is |
| 6 // callable only on the Pepper thread. | 6 // callable only on the Pepper thread. |
| 7 | 7 |
| 8 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ | 8 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ |
| 9 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ | 9 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "media/base/video_frame.h" | |
| 16 #include "ppapi/cpp/graphics_2d.h" | 15 #include "ppapi/cpp/graphics_2d.h" |
| 17 #include "ppapi/cpp/point.h" | 16 #include "ppapi/cpp/point.h" |
| 18 #include "remoting/client/chromoting_view.h" | 17 #include "remoting/client/chromoting_view.h" |
| 19 #include "remoting/client/frame_consumer.h" | 18 #include "remoting/client/frame_consumer.h" |
| 20 | 19 |
| 21 namespace remoting { | 20 namespace remoting { |
| 22 | 21 |
| 23 class ChromotingInstance; | 22 class ChromotingInstance; |
| 24 class ClientContext; | 23 class ClientContext; |
| 25 | 24 |
| 26 class PepperView : public ChromotingView, | 25 class PepperView : public ChromotingView, |
| 27 public FrameConsumer { | 26 public FrameConsumer { |
| 28 public: | 27 public: |
| 29 // Constructs a PepperView for the |instance|. The |instance| and | 28 // Constructs a PepperView for the |instance|. The |instance| and |
| 30 // |context| must outlive this class. | 29 // |context| must outlive this class. |
| 31 PepperView(ChromotingInstance* instance, ClientContext* context); | 30 PepperView(ChromotingInstance* instance, ClientContext* context); |
| 32 virtual ~PepperView(); | 31 virtual ~PepperView(); |
| 33 | 32 |
| 34 // ChromotingView implementation. | 33 // ChromotingView implementation. |
| 35 virtual bool Initialize() OVERRIDE; | 34 virtual bool Initialize() OVERRIDE; |
| 36 virtual void TearDown() OVERRIDE; | 35 virtual void TearDown() OVERRIDE; |
| 37 virtual void Paint() OVERRIDE; | 36 virtual void Paint() OVERRIDE; |
| 38 virtual void SetSolidFill(uint32 color) OVERRIDE; | 37 virtual void SetSolidFill(uint32 color) OVERRIDE; |
| 39 virtual void UnsetSolidFill() OVERRIDE; | 38 virtual void UnsetSolidFill() OVERRIDE; |
| 40 virtual void SetConnectionState( | 39 virtual void SetConnectionState( |
| 41 protocol::ConnectionToHost::State state, | 40 protocol::ConnectionToHost::State state, |
| 42 protocol::ConnectionToHost::Error error) OVERRIDE; | 41 protocol::ConnectionToHost::Error error) OVERRIDE; |
| 43 | 42 |
| 44 // FrameConsumer implementation. | 43 // FrameConsumer implementation. |
| 45 virtual void AllocateFrame(media::VideoFrame::Format format, | 44 virtual void OnFrameReady(const SkISize& screen_size, |
| 46 const SkISize& size, | 45 SkISize* view_size_out, |
| 47 scoped_refptr<media::VideoFrame>* frame_out, | 46 SkIRect* clip_area_out, |
| 48 const base::Closure& done) OVERRIDE; | 47 scoped_ptr<pp::ImageData>* backing_store_out, |
| 49 virtual void ReleaseFrame(media::VideoFrame* frame) OVERRIDE; | 48 const base::Closure& done) OVERRIDE; |
| 50 virtual void OnPartialFrameOutput(media::VideoFrame* frame, | 49 virtual void OnPaintDone(scoped_ptr<pp::ImageData> backing_store, |
| 51 SkRegion* region, | 50 scoped_ptr<SkRegion> updated_region) OVERRIDE; |
| 52 const base::Closure& done) OVERRIDE; | |
| 53 | 51 |
| 54 // Sets the display size of this view. Returns true if plugin size has | 52 // Sets the display size and clipping area of this view. Returns true |
| 55 // changed, false otherwise. | 53 // if plugin size or clipping area has changed, false otherwise. |
| 56 bool SetViewSize(const SkISize& plugin_size); | 54 bool SetView(const SkISize& view_size, const SkIRect& clip_area); |
| 57 | 55 |
| 58 // Return the client view and original host dimensions. | 56 // Return the client view and original host dimensions. |
| 59 const SkISize& get_view_size() const { | 57 const SkISize& get_view_size() const { |
| 60 return view_size_; | 58 return view_size_; |
| 61 } | 59 } |
| 62 const SkISize& get_host_size() const { | 60 const SkISize& get_screen_size() const { |
| 63 return host_size_; | 61 return screen_size_; |
| 64 } | 62 } |
| 65 | 63 |
| 66 private: | 64 private: |
| 67 void OnPaintDone(base::Time paint_start); | 65 void OnFlushDone(base::Time paint_start); |
| 68 | 66 |
| 69 // Set the dimension of the entire host screen. | 67 // Set the dimension of the entire host screen. |
| 70 void SetHostSize(const SkISize& host_size); | 68 void SetScreenSize(const SkISize& screen_size); |
| 71 | |
| 72 void PaintFrame(media::VideoFrame* frame, const SkRegion& region); | |
| 73 | |
| 74 // Render the rectangle of |frame| to the backing store. | |
| 75 // Returns true if this rectangle is not clipped. | |
| 76 bool PaintRect(media::VideoFrame* frame, const SkIRect& rect); | |
| 77 | |
| 78 // Blanks out a rectangle in an image. | |
| 79 void BlankRect(pp::ImageData& image_data, const pp::Rect& rect); | |
| 80 | 69 |
| 81 // Perform a flush on the graphics context. | 70 // Perform a flush on the graphics context. |
| 82 void FlushGraphics(base::Time paint_start); | 71 void FlushGraphics(base::Time paint_start); |
| 83 | 72 |
| 84 // Reference to the creating plugin instance. Needed for interacting with | 73 // Reference to the creating plugin instance. Needed for interacting with |
| 85 // pepper. Marking explicitly as const since it must be initialized at | 74 // pepper. Marking explicitly as const since it must be initialized at |
| 86 // object creation, and never change. | 75 // object creation, and never change. |
| 87 ChromotingInstance* const instance_; | 76 ChromotingInstance* const instance_; |
| 88 | 77 |
| 89 // Context should be constant for the lifetime of the plugin. | 78 // Context should be constant for the lifetime of the plugin. |
| 90 ClientContext* const context_; | 79 ClientContext* const context_; |
| 91 | 80 |
| 92 pp::Graphics2D graphics2d_; | 81 pp::Graphics2D graphics2d_; |
| 93 | 82 |
| 94 // A backing store that saves the current desktop image. | 83 // A backing store that saves the current desktop image. |
| 95 scoped_ptr<pp::ImageData> backing_store_; | 84 scoped_ptr<pp::ImageData> backing_store_; |
| 96 | 85 |
| 97 // True if there is pending paint commands in Pepper's queue. This is set to | 86 // True if there is pending paint commands in Pepper's queue. This is set to |
| 98 // true if the last flush returns a PP_ERROR_INPROGRESS error. | 87 // true if the last flush returns a PP_ERROR_INPROGRESS error. |
| 99 bool flush_blocked_; | 88 bool flush_blocked_; |
| 100 | 89 |
| 90 // True is view dimensions or clipping area has been changed. |
| 91 bool view_changed_; |
| 92 |
| 101 // The size of the plugin element. | 93 // The size of the plugin element. |
| 102 SkISize view_size_; | 94 SkISize view_size_; |
| 103 | 95 |
| 96 // The current clip area rectangle. |
| 97 SkIRect clip_area_; |
| 98 |
| 104 // The size of the host screen. | 99 // The size of the host screen. |
| 105 SkISize host_size_; | 100 SkISize screen_size_; |
| 106 | 101 |
| 107 bool is_static_fill_; | 102 bool is_static_fill_; |
| 108 uint32 static_fill_color_; | 103 uint32 static_fill_color_; |
| 109 | 104 |
| 110 base::WeakPtrFactory<PepperView> weak_factory_; | 105 base::WeakPtrFactory<PepperView> weak_factory_; |
| 111 | 106 |
| 112 DISALLOW_COPY_AND_ASSIGN(PepperView); | 107 DISALLOW_COPY_AND_ASSIGN(PepperView); |
| 113 }; | 108 }; |
| 114 | 109 |
| 115 } // namespace remoting | 110 } // namespace remoting |
| 116 | 111 |
| 117 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ | 112 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ |
| OLD | NEW |