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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_
6 #define CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "cc/output/software_output_device.h"
13 #include "content/public/renderer/render_thread.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
20 // This class can be created only on the main thread, but then becomes pinned
21 // to a fixed thread when BindToClient is called.
22 class CompositorSoftwareOutputDevice
23 : NON_EXPORTED_BASE(public cc::SoftwareOutputDevice),
24 NON_EXPORTED_BASE(public base::NonThreadSafe) {
26 CompositorSoftwareOutputDevice();
27 virtual ~CompositorSoftwareOutputDevice();
29 virtual void Resize(const gfx::Size& size) OVERRIDE;
31 virtual SkCanvas* BeginPaint(const gfx::Rect& damage_rect) OVERRIDE;
32 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE;
33 virtual void EnsureBackbuffer() OVERRIDE;
34 virtual void DiscardBackbuffer() OVERRIDE;
36 virtual void ReclaimSoftwareFrame(unsigned id) OVERRIDE;
39 // Internal buffer class that manages shared memory lifetime and ownership.
40 // It also tracks buffers' history so we can calculate what's the minimum
41 // damage rect difference between any two given buffers (see SetParent and
42 // FindDamageDifferenceFrom).
45 explicit Buffer(unsigned id, scoped_ptr<base::SharedMemory> mem);
48 unsigned id() const { return id_; }
50 void* memory() const { return mem_->memory(); }
51 base::SharedMemoryHandle handle() const { return mem_->handle(); }
52 base::SharedMemory* shared_memory() const { return mem_.get(); }
54 bool free() const { return free_; }
55 void SetFree(bool free) { free_ = free; }
57 Buffer* parent() const { return parent_; }
58 void SetParent(Buffer* parent, const gfx::Rect& damage);
60 bool FindDamageDifferenceFrom(Buffer* buffer, SkRegion* result) const;
64 scoped_ptr<base::SharedMemory> mem_;
69 DISALLOW_COPY_AND_ASSIGN(Buffer);
74 CompareById(unsigned id) : id_(id) {}
76 bool operator()(const Buffer* buffer) const {
77 return buffer->id() == id_;
85 Buffer* CreateBuffer();
86 size_t FindFreeBuffer(size_t hint);
88 size_t current_index_;
89 unsigned next_buffer_id_;
90 ScopedVector<Buffer> buffers_;
91 ScopedVector<Buffer> awaiting_ack_;
93 RenderThread* render_thread_;
96 } // namespace content
98 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_