| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ | 5 #ifndef CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ |
| 6 #define CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ | 6 #define CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/memory/shared_memory.h" |
| 9 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 10 #include "cc/output/software_output_device.h" | 12 #include "cc/output/software_output_device.h" |
| 13 #include "content/public/renderer/render_thread.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 | 15 |
| 16 class SkRegion; |
| 17 |
| 13 namespace content { | 18 namespace content { |
| 14 | 19 |
| 15 // This class can be created only on the main thread, but then becomes pinned | 20 // This class can be created only on the main thread, but then becomes pinned |
| 16 // to a fixed thread when BindToClient is called. | 21 // to a fixed thread when BindToClient is called. |
| 17 class CompositorSoftwareOutputDevice | 22 class CompositorSoftwareOutputDevice |
| 18 : NON_EXPORTED_BASE(public cc::SoftwareOutputDevice), | 23 : NON_EXPORTED_BASE(public cc::SoftwareOutputDevice), |
| 19 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 24 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 20 public: | 25 public: |
| 21 CompositorSoftwareOutputDevice(); | 26 CompositorSoftwareOutputDevice(); |
| 22 virtual ~CompositorSoftwareOutputDevice(); | 27 virtual ~CompositorSoftwareOutputDevice(); |
| 23 | 28 |
| 24 virtual void Resize(gfx::Size size) OVERRIDE; | 29 virtual void Resize(gfx::Size size) OVERRIDE; |
| 25 | 30 |
| 26 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE; | 31 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE; |
| 27 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE; | 32 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE; |
| 28 | 33 |
| 29 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE; | 34 virtual void ReclaimSoftwareFrame(unsigned id) OVERRIDE; |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 class DIB { | 37 // Internal buffer class that manages shared memory lifetime and ownership. |
| 38 // It also tracks buffers' history so we can calculate what's the minimum |
| 39 // damage rect difference between any two given buffers (see SetParent and |
| 40 // FindDamageDifferenceFrom). |
| 41 class Buffer { |
| 33 public: | 42 public: |
| 34 explicit DIB(size_t size); | 43 explicit Buffer(unsigned id, scoped_ptr<base::SharedMemory> mem); |
| 35 ~DIB(); | 44 ~Buffer(); |
| 36 | 45 |
| 37 TransportDIB* dib() const { | 46 unsigned id() const { return id_; } |
| 38 return dib_; | 47 |
| 39 } | 48 void* memory() const { return mem_->memory(); } |
| 49 base::SharedMemoryHandle handle() const { return mem_->handle(); } |
| 50 |
| 51 bool free() const { return free_; } |
| 52 void SetFree(bool free) { free_ = free; } |
| 53 |
| 54 Buffer* parent() const { return parent_; } |
| 55 void SetParent(Buffer* parent, const gfx::Rect& damage); |
| 56 |
| 57 bool FindDamageDifferenceFrom(Buffer* buffer, SkRegion* result) const; |
| 40 | 58 |
| 41 private: | 59 private: |
| 42 TransportDIB* dib_; | 60 const unsigned id_; |
| 61 scoped_ptr<base::SharedMemory> mem_; |
| 62 bool free_; |
| 63 Buffer* parent_; |
| 64 gfx::Rect damage_; |
| 43 | 65 |
| 44 DISALLOW_COPY_AND_ASSIGN(DIB); | 66 DISALLOW_COPY_AND_ASSIGN(Buffer); |
| 45 }; | 67 }; |
| 46 | 68 |
| 47 class CompareById { | 69 class CompareById { |
| 48 public: | 70 public: |
| 49 CompareById(const TransportDIB::Id& id) : id_(id) {} | 71 CompareById(unsigned id) : id_(id) {} |
| 50 | 72 |
| 51 bool operator()(const DIB* dib) const { | 73 bool operator()(const Buffer* buffer) const { |
| 52 return dib->dib() && dib->dib()->id() == id_; | 74 return buffer->id() == id_; |
| 53 } | 75 } |
| 54 | 76 |
| 55 private: | 77 private: |
| 56 TransportDIB::Id id_; | 78 const unsigned id_; |
| 57 }; | 79 }; |
| 58 | 80 |
| 59 DIB* CreateDIB(); | 81 unsigned GetNextId(); |
| 82 Buffer* CreateBuffer(); |
| 83 size_t FindFreeBuffer(size_t hint); |
| 60 | 84 |
| 61 int front_buffer_; | 85 size_t current_index_; |
| 62 int num_free_buffers_; | 86 unsigned next_buffer_id_; |
| 63 ScopedVector<DIB> dibs_; | 87 ScopedVector<Buffer> buffers_; |
| 64 ScopedVector<DIB> awaiting_ack_; | 88 ScopedVector<Buffer> awaiting_ack_; |
| 65 SkBitmap bitmap_; | 89 SkBitmap bitmap_; |
| 90 RenderThread* render_thread_; |
| 66 }; | 91 }; |
| 67 | 92 |
| 68 } // namespace content | 93 } // namespace content |
| 69 | 94 |
| 70 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ | 95 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_ |
| OLD | NEW |