| 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 <list> | 11 #include <list> | 
| 12 | 12 | 
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" | 
| 14 #include "ppapi/cpp/graphics_2d.h" | 14 #include "ppapi/cpp/graphics_2d.h" | 
| 15 #include "ppapi/cpp/view.h" | 15 #include "ppapi/cpp/view.h" | 
| 16 #include "ppapi/cpp/point.h" | 16 #include "ppapi/cpp/point.h" | 
| 17 #include "remoting/client/frame_consumer.h" | 17 #include "remoting/client/frame_consumer.h" | 
| 18 | 18 | 
| 19 namespace base { | 19 namespace base { | 
| 20 class Time; | 20 class Time; | 
| 21 }  // namespace base | 21 }  // namespace base | 
| 22 | 22 | 
| 23 namespace remoting { | 23 namespace remoting { | 
| 24 | 24 | 
| 25 class ChromotingInstance; | 25 class ChromotingInstance; | 
| 26 class ClientContext; | 26 class ClientContext; | 
| 27 class FrameProducer; | 27 class FrameProducer; | 
|  | 28 class ImageBuffer; | 
| 28 | 29 | 
| 29 class PepperView : public FrameConsumer, | 30 class PepperView : public FrameConsumer, | 
| 30                    public base::SupportsWeakPtr<PepperView> { | 31                    public base::SupportsWeakPtr<PepperView> { | 
| 31  public: | 32  public: | 
| 32   // Constructs a PepperView for the |instance|. The |instance|, |context| | 33   // Constructs a PepperView for the |instance|. The |instance|, |context| | 
| 33   // and |producer| must outlive this class. | 34   // and |producer| must outlive this class. | 
| 34   PepperView(ChromotingInstance* instance, | 35   PepperView(ChromotingInstance* instance, | 
| 35              ClientContext* context, | 36              ClientContext* context, | 
| 36              FrameProducer* producer); | 37              FrameProducer* producer); | 
| 37   virtual ~PepperView(); | 38   virtual ~PepperView(); | 
| 38 | 39 | 
| 39   // FrameConsumer implementation. | 40   // FrameConsumer implementation. | 
| 40   virtual void ApplyBuffer(const SkISize& view_size, | 41   virtual void ApplyBuffer(const SkISize& view_size, | 
| 41                            const SkIRect& clip_area, | 42                            const SkIRect& clip_area, | 
| 42                            pp::ImageData* buffer, | 43                            ImageBuffer* buffer, | 
| 43                            const SkRegion& region) OVERRIDE; | 44                            const SkRegion& region) OVERRIDE; | 
| 44   virtual void ReturnBuffer(pp::ImageData* buffer) OVERRIDE; | 45   virtual void ReturnBuffer(ImageBuffer* buffer) OVERRIDE; | 
| 45   virtual void SetSourceSize(const SkISize& source_size, | 46   virtual void SetSourceSize(const SkISize& source_size, | 
| 46                              const SkIPoint& dpi) OVERRIDE; | 47                              const SkIPoint& dpi) OVERRIDE; | 
| 47 | 48 | 
| 48   // Updates the PepperView's size & clipping area, taking into account the | 49   // Updates the PepperView's size & clipping area, taking into account the | 
| 49   // DIP-to-device scale factor. | 50   // DIP-to-device scale factor. | 
| 50   void SetView(const pp::View& view); | 51   void SetView(const pp::View& view); | 
| 51 | 52 | 
| 52   // Returns the dimensions of the most recently displayed frame, in pixels. | 53   // Returns the dimensions of the most recently displayed frame, in pixels. | 
| 53   const SkISize& get_source_size() const { | 54   const SkISize& get_source_size() const { | 
| 54     return source_size_; | 55     return source_size_; | 
| 55   } | 56   } | 
| 56 | 57 | 
| 57   // Return the dimensions of the view in Density Independent Pixels (DIPs). | 58   // Return the dimensions of the view in Density Independent Pixels (DIPs). | 
| 58   // Note that there may be multiple device pixels per DIP. | 59   // Note that there may be multiple device pixels per DIP. | 
| 59   const SkISize& get_view_size_dips() const { | 60   const SkISize& get_view_size_dips() const { | 
| 60     return dips_size_; | 61     return dips_size_; | 
| 61   } | 62   } | 
| 62 | 63 | 
| 63  private: | 64  private: | 
| 64   // Allocates a new frame buffer to supply to the FrameProducer to render into. | 65   // Allocates a new frame buffer to supply to the FrameProducer to render into. | 
| 65   // Returns NULL if the maximum number of buffers has already been allocated. | 66   // Returns NULL if the maximum number of buffers has already been allocated. | 
| 66   pp::ImageData* AllocateBuffer(); | 67   ImageBuffer* AllocateBuffer(); | 
| 67 | 68 | 
| 68   // Frees a frame buffer previously allocated by AllocateBuffer. | 69   // Frees a frame buffer previously allocated by AllocateBuffer. | 
| 69   void FreeBuffer(pp::ImageData* buffer); | 70   void FreeBuffer(ImageBuffer* buffer); | 
| 70 | 71 | 
| 71   // Allocates buffers and passes them to the FrameProducer to render into until | 72   // Allocates buffers and passes them to the FrameProducer to render into until | 
| 72   // the maximum number of buffers are in-flight. | 73   // the maximum number of buffers are in-flight. | 
| 73   void InitiateDrawing(); | 74   void InitiateDrawing(); | 
| 74 | 75 | 
| 75   // Renders the parts of |buffer| identified by |region| to the view.  If the | 76   // Renders the parts of |buffer| identified by |region| to the view.  If the | 
| 76   // clip area of the view has changed since the buffer was generated then | 77   // clip area of the view has changed since the buffer was generated then | 
| 77   // FrameProducer is supplied the missed parts of |region|.  The FrameProducer | 78   // FrameProducer is supplied the missed parts of |region|.  The FrameProducer | 
| 78   // will be supplied a new buffer when FlushBuffer() completes. | 79   // will be supplied a new buffer when FlushBuffer() completes. | 
| 79   void FlushBuffer(const SkIRect& clip_area, | 80   void FlushBuffer(const SkIRect& clip_area, | 
| 80                    pp::ImageData* buffer, | 81                    ImageBuffer* buffer, | 
| 81                    const SkRegion& region); | 82                    const SkRegion& region); | 
| 82 | 83 | 
| 83   // Handles completion of FlushBuffer(), triggering a new buffer to be | 84   // Handles completion of FlushBuffer(), triggering a new buffer to be | 
| 84   // returned to FrameProducer for rendering. | 85   // returned to FrameProducer for rendering. | 
| 85   void OnFlushDone(base::Time paint_start, pp::ImageData* buffer, int result); | 86   void OnFlushDone(base::Time paint_start, ImageBuffer* buffer, int result); | 
| 86 | 87 | 
| 87   // Reference to the creating plugin instance. Needed for interacting with | 88   // Reference to the creating plugin instance. Needed for interacting with | 
| 88   // pepper.  Marking explicitly as const since it must be initialized at | 89   // pepper.  Marking explicitly as const since it must be initialized at | 
| 89   // object creation, and never change. | 90   // object creation, and never change. | 
| 90   ChromotingInstance* const instance_; | 91   ChromotingInstance* const instance_; | 
| 91 | 92 | 
| 92   // Context should be constant for the lifetime of the plugin. | 93   // Context should be constant for the lifetime of the plugin. | 
| 93   ClientContext* const context_; | 94   ClientContext* const context_; | 
| 94 | 95 | 
| 95   pp::Graphics2D graphics2d_; | 96   pp::Graphics2D graphics2d_; | 
| 96 | 97 | 
| 97   FrameProducer* producer_; | 98   FrameProducer* producer_; | 
| 98 | 99 | 
| 99   // List of allocated image buffers. | 100   // List of allocated image buffers. | 
| 100   std::list<pp::ImageData*> buffers_; | 101   std::list<ImageBuffer*> buffers_; | 
| 101 | 102 | 
| 102   // Queued buffer to paint, with clip area and dirty region in device pixels. | 103   // Queued buffer to paint, with clip area and dirty region in device pixels. | 
| 103   pp::ImageData* merge_buffer_; | 104   ImageBuffer* merge_buffer_; | 
| 104   SkIRect merge_clip_area_; | 105   SkIRect merge_clip_area_; | 
| 105   SkRegion merge_region_; | 106   SkRegion merge_region_; | 
| 106 | 107 | 
| 107   // View size in Density Independent Pixels (DIPs). | 108   // View size in Density Independent Pixels (DIPs). | 
| 108   SkISize dips_size_; | 109   SkISize dips_size_; | 
| 109 | 110 | 
| 110   // Scale factor from DIPs to device pixels. | 111   // Scale factor from DIPs to device pixels. | 
| 111   float dips_to_device_scale_; | 112   float dips_to_device_scale_; | 
| 112 | 113 | 
| 113   // View size in output pixels. This is the size at which FrameProducer must | 114   // View size in output pixels. This is the size at which FrameProducer must | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 135 | 136 | 
| 136   // True after the first call to ApplyBuffer(). | 137   // True after the first call to ApplyBuffer(). | 
| 137   bool frame_received_; | 138   bool frame_received_; | 
| 138 | 139 | 
| 139   DISALLOW_COPY_AND_ASSIGN(PepperView); | 140   DISALLOW_COPY_AND_ASSIGN(PepperView); | 
| 140 }; | 141 }; | 
| 141 | 142 | 
| 142 }  // namespace remoting | 143 }  // namespace remoting | 
| 143 | 144 | 
| 144 #endif  // REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ | 145 #endif  // REMOTING_CLIENT_PLUGIN_PEPPER_VIEW_H_ | 
| OLD | NEW | 
|---|