blob: d027f19b548a76763c8c00816e48bf22ef479a36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_SURFACE_ACCELERATED_SURFACE_WIN_H_
#define UI_GFX_SURFACE_ACCELERATED_SURFACE_WIN_H_
#pragma once
#include <d3d9.h>
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/win/scoped_comptr.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/size.h"
#include "ui/gfx/surface/surface_export.h"
class PresentThread;
class AcceleratedPresenter
: public base::RefCountedThreadSafe<AcceleratedPresenter> {
public:
typedef base::Callback<void(bool)> CompletionTaskl;
AcceleratedPresenter();
// The public member functions are called on the main thread.
void AsyncPresentAndAcknowledge(
gfx::NativeWindow window,
const gfx::Size& size,
int64 surface_id,
const base::Callback<void(bool)>& completion_task);
bool Present(gfx::NativeWindow window);
void Suspend();
void WaitForPendingTasks();
private:
friend class base::RefCountedThreadSafe<AcceleratedPresenter>;
~AcceleratedPresenter();
// These member functions are called on the PresentThread with which the
// presenter has affinity.
void DoPresentAndAcknowledge(
gfx::NativeWindow window,
const gfx::Size& size,
int64 surface_id,
const base::Callback<void(bool)>& completion_task);
void DoSuspend();
// The thread with which this presenter has affinity.
PresentThread* const present_thread_;
// The lock is taken while any thread is calling the object, except those that
// simply post from the main thread to the present thread via the immutable
// present_thread_ member.
base::Lock lock_;
// The current size of the swap chain. This is only accessed on the thread
// with which the surface has affinity.
gfx::Size size_;
// The swap chain is presented to the child window. Copy semantics
// are used so it is possible to represent it to quickly validate the window.
base::win::ScopedComPtr<IDirect3DSwapChain9> swap_chain_;
DISALLOW_COPY_AND_ASSIGN(AcceleratedPresenter);
};
class SURFACE_EXPORT AcceleratedSurface {
public:
AcceleratedSurface();
~AcceleratedSurface();
// Schedule a frame to be presented. The completion callback will be invoked
// when it is safe to write to the surface on another thread. The lock for
// this surface will be held while the completion callback runs.
void AsyncPresentAndAcknowledge(
gfx::NativeWindow window,
const gfx::Size& size,
int64 surface_id,
const base::Callback<void(bool)>& completion_task);
// Synchronously present a frame with no acknowledgement.
bool Present(gfx::NativeWindow window);
// Temporarily release resources until a new surface is asynchronously
// presented. Present will not be able to represent the last surface after
// calling this and will return false.
void Suspend();
private:
scoped_refptr<AcceleratedPresenter> presenter_;
DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface);
};
#endif // UI_GFX_SURFACE_ACCELERATED_SURFACE_WIN_H_
|