OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #ifndef CC_RESOURCES_TEXTURE_UPLOADER_H_ | |
6 #define CC_RESOURCES_TEXTURE_UPLOADER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "cc/base/scoped_ptr_deque.h" | |
13 #include "cc/resources/resource_provider.h" | |
14 | |
15 namespace gfx { | |
16 class Rect; | |
17 class Size; | |
18 class Vector2d; | |
19 } | |
20 | |
21 namespace gpu { | |
22 namespace gles2 { | |
23 class GLES2Interface; | |
24 } | |
25 } | |
26 | |
27 namespace cc { | |
28 | |
29 class TextureUploader { | |
30 public: | |
31 static scoped_ptr<TextureUploader> Create(gpu::gles2::GLES2Interface* gl) { | |
32 return make_scoped_ptr(new TextureUploader(gl)); | |
33 } | |
34 ~TextureUploader(); | |
35 | |
36 size_t NumBlockingUploads(); | |
37 void MarkPendingUploadsAsNonBlocking(); | |
38 double EstimatedTexturesPerSecond(); | |
39 | |
40 // Let content_rect be a rectangle, and let content_rect be a sub-rectangle of | |
41 // content_rect, expressed in the same coordinate system as content_rect. Let | |
42 // image be a buffer for content_rect. This function will copy the region | |
43 // corresponding to source_rect to dest_offset in this sub-image. | |
44 void Upload(const uint8* image, | |
45 const gfx::Rect& content_rect, | |
46 const gfx::Rect& source_rect, | |
47 gfx::Vector2d dest_offset, | |
48 ResourceFormat format, | |
49 const gfx::Size& size); | |
50 | |
51 void Flush(); | |
52 void ReleaseCachedQueries(); | |
53 | |
54 private: | |
55 class Query { | |
56 public: | |
57 static scoped_ptr<Query> Create(gpu::gles2::GLES2Interface* gl) { | |
58 return make_scoped_ptr(new Query(gl)); | |
59 } | |
60 | |
61 virtual ~Query(); | |
62 | |
63 void Begin(); | |
64 void End(); | |
65 bool IsPending(); | |
66 unsigned Value(); | |
67 size_t TexturesUploaded(); | |
68 void mark_as_non_blocking() { is_non_blocking_ = true; } | |
69 bool is_non_blocking() const { return is_non_blocking_; } | |
70 | |
71 private: | |
72 explicit Query(gpu::gles2::GLES2Interface* gl); | |
73 | |
74 gpu::gles2::GLES2Interface* gl_; | |
75 unsigned query_id_; | |
76 unsigned value_; | |
77 bool has_value_; | |
78 bool is_non_blocking_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(Query); | |
81 }; | |
82 | |
83 explicit TextureUploader(gpu::gles2::GLES2Interface* gl); | |
84 | |
85 void BeginQuery(); | |
86 void EndQuery(); | |
87 void ProcessQueries(); | |
88 | |
89 void UploadWithTexSubImage(const uint8* image, | |
90 const gfx::Rect& image_rect, | |
91 const gfx::Rect& source_rect, | |
92 gfx::Vector2d dest_offset, | |
93 ResourceFormat format); | |
94 void UploadWithMapTexSubImage(const uint8* image, | |
95 const gfx::Rect& image_rect, | |
96 const gfx::Rect& source_rect, | |
97 gfx::Vector2d dest_offset, | |
98 ResourceFormat format); | |
99 void UploadWithTexImageETC1(const uint8* image, const gfx::Size& size); | |
100 | |
101 gpu::gles2::GLES2Interface* gl_; | |
102 ScopedPtrDeque<Query> pending_queries_; | |
103 ScopedPtrDeque<Query> available_queries_; | |
104 std::multiset<double> textures_per_second_history_; | |
105 size_t num_blocking_texture_uploads_; | |
106 | |
107 size_t sub_image_size_; | |
108 scoped_ptr<uint8[]> sub_image_; | |
109 | |
110 size_t num_texture_uploads_since_last_flush_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(TextureUploader); | |
113 }; | |
114 | |
115 } // namespace cc | |
116 | |
117 #endif // CC_RESOURCES_TEXTURE_UPLOADER_H_ | |
OLD | NEW |