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
99
100
101
102
|
// Copyright 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 CC_TEXTURE_UPLOADER_H_
#define CC_TEXTURE_UPLOADER_H_
#include "IntRect.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "cc/scoped_ptr_deque.h"
#include <set>
#include "third_party/khronos/GLES2/gl2.h"
namespace WebKit {
class WebGraphicsContext3D;
}
namespace cc {
class TextureUploader {
public:
static scoped_ptr<TextureUploader> create(
WebKit::WebGraphicsContext3D* context, bool useMapTexSubImage)
{
return make_scoped_ptr(new TextureUploader(context, useMapTexSubImage));
}
~TextureUploader();
size_t numBlockingUploads();
void markPendingUploadsAsNonBlocking();
double estimatedTexturesPerSecond();
// Let imageRect be a rectangle, and let sourceRect be a sub-rectangle of
// imageRect, expressed in the same coordinate system as imageRect. Let
// image be a buffer for imageRect. This function will copy the region
// corresponding to sourceRect to destOffset in this sub-image.
void upload(const uint8_t* image,
const IntRect& content_rect,
const IntRect& source_rect,
const IntSize& dest_offset,
GLenum format,
IntSize size);
private:
class Query {
public:
static scoped_ptr<Query> create(WebKit::WebGraphicsContext3D* context) { return make_scoped_ptr(new Query(context)); }
virtual ~Query();
void begin();
void end();
bool isPending();
unsigned value();
size_t texturesUploaded();
void markAsNonBlocking();
bool isNonBlocking();
private:
explicit Query(WebKit::WebGraphicsContext3D*);
WebKit::WebGraphicsContext3D* m_context;
unsigned m_queryId;
unsigned m_value;
bool m_hasValue;
bool m_isNonBlocking;
};
TextureUploader(WebKit::WebGraphicsContext3D*, bool useMapTexSubImage);
void beginQuery();
void endQuery();
void processQueries();
void uploadWithTexSubImage(const uint8_t* image,
const IntRect& image_rect,
const IntRect& source_rect,
const IntSize& dest_offset,
GLenum format);
void uploadWithMapTexSubImage(const uint8_t* image,
const IntRect& image_rect,
const IntRect& source_rect,
const IntSize& dest_offset,
GLenum format);
WebKit::WebGraphicsContext3D* m_context;
ScopedPtrDeque<Query> m_pendingQueries;
ScopedPtrDeque<Query> m_availableQueries;
std::multiset<double> m_texturesPerSecondHistory;
size_t m_numBlockingTextureUploads;
bool m_useMapTexSubImage;
size_t m_subImageSize;
scoped_array<uint8_t> m_subImage;
DISALLOW_COPY_AND_ASSIGN(TextureUploader);
};
} // namespace cc
#endif // CC_TEXTURE_UPLOADER_H_
|