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 "cc/resources/shared_bitmap.h"
14 #include "content/public/renderer/render_thread.h"
15 #include "third_party/skia/include/core/SkBitmap.h"
20 class SharedBitmapManager
;
25 // This class can be created only on the main thread, but then becomes pinned
26 // to a fixed thread when BindToClient is called.
27 class CompositorSoftwareOutputDevice
28 : NON_EXPORTED_BASE(public cc::SoftwareOutputDevice
),
29 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
31 CompositorSoftwareOutputDevice();
32 ~CompositorSoftwareOutputDevice() override
;
34 void Resize(const gfx::Size
& pixel_size
, float scale_factor
) override
;
36 SkCanvas
* BeginPaint(const gfx::Rect
& damage_rect
) override
;
37 void EndPaint(cc::SoftwareFrameData
* frame_data
) override
;
38 void EnsureBackbuffer() override
;
39 void DiscardBackbuffer() override
;
41 void ReclaimSoftwareFrame(unsigned id
) override
;
44 // Internal buffer class that manages shared memory lifetime and ownership.
45 // It also tracks buffers' history so we can calculate what's the minimum
46 // damage rect difference between any two given buffers (see SetParent and
47 // FindDamageDifferenceFrom).
50 explicit Buffer(unsigned id
, scoped_ptr
<cc::SharedBitmap
> bitmap
);
53 unsigned id() const { return id_
; }
55 void* memory() const { return shared_bitmap_
->pixels(); }
56 cc::SharedBitmapId
shared_bitmap_id() const { return shared_bitmap_
->id(); }
58 bool free() const { return free_
; }
59 void SetFree(bool free
) { free_
= free
; }
61 Buffer
* parent() const { return parent_
; }
62 void SetParent(Buffer
* parent
, const gfx::Rect
& damage
);
64 bool FindDamageDifferenceFrom(Buffer
* buffer
, SkRegion
* result
) const;
68 scoped_ptr
<cc::SharedBitmap
> shared_bitmap_
;
73 DISALLOW_COPY_AND_ASSIGN(Buffer
);
78 CompareById(unsigned id
) : id_(id
) {}
80 bool operator()(const Buffer
* buffer
) const {
81 return buffer
->id() == id_
;
89 Buffer
* CreateBuffer();
90 size_t FindFreeBuffer(size_t hint
);
92 size_t current_index_
;
93 unsigned next_buffer_id_
;
94 ScopedVector
<Buffer
> buffers_
;
95 ScopedVector
<Buffer
> awaiting_ack_
;
96 cc::SharedBitmapManager
* shared_bitmap_manager_
;
99 } // namespace content
101 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_H_