OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TEXTURE_UPLOADER_H_ | 5 #ifndef CC_TEXTURE_UPLOADER_H_ |
6 #define CC_TEXTURE_UPLOADER_H_ | 6 #define CC_TEXTURE_UPLOADER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "cc/scoped_ptr_deque.h" | 10 #include "cc/scoped_ptr_deque.h" |
11 #include <set> | 11 #include <set> |
12 #include "third_party/khronos/GLES2/gl2.h" | 12 #include "third_party/khronos/GLES2/gl2.h" |
13 | 13 |
14 namespace WebKit { | 14 namespace WebKit { |
15 class WebGraphicsContext3D; | 15 class WebGraphicsContext3D; |
16 } | 16 } |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 class Rect; | 19 class Rect; |
20 class Size; | 20 class Size; |
21 class Vector2d; | 21 class Vector2d; |
22 } | 22 } |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 | 25 |
26 class TextureUploader { | 26 class TextureUploader { |
27 public: | 27 public: |
28 static scoped_ptr<TextureUploader> create( | 28 static scoped_ptr<TextureUploader> create( |
29 WebKit::WebGraphicsContext3D* context, bool useMapTexSubImage) | 29 WebKit::WebGraphicsContext3D* context, |
| 30 bool useMapTexSubImage, |
| 31 bool useShallowFlush) |
30 { | 32 { |
31 return make_scoped_ptr(new TextureUploader(context, useMapTexSubImage)); | 33 return make_scoped_ptr( |
| 34 new TextureUploader(context, useMapTexSubImage, useShallowFlush)); |
32 } | 35 } |
33 ~TextureUploader(); | 36 ~TextureUploader(); |
34 | 37 |
35 size_t numBlockingUploads(); | 38 size_t numBlockingUploads(); |
36 void markPendingUploadsAsNonBlocking(); | 39 void markPendingUploadsAsNonBlocking(); |
37 double estimatedTexturesPerSecond(); | 40 double estimatedTexturesPerSecond(); |
38 | 41 |
39 // Let imageRect be a rectangle, and let sourceRect be a sub-rectangle of | 42 // Let imageRect be a rectangle, and let sourceRect be a sub-rectangle of |
40 // imageRect, expressed in the same coordinate system as imageRect. Let | 43 // imageRect, expressed in the same coordinate system as imageRect. Let |
41 // image be a buffer for imageRect. This function will copy the region | 44 // image be a buffer for imageRect. This function will copy the region |
42 // corresponding to sourceRect to destOffset in this sub-image. | 45 // corresponding to sourceRect to destOffset in this sub-image. |
43 void upload(const uint8* image, | 46 void upload(const uint8* image, |
44 const gfx::Rect& content_rect, | 47 const gfx::Rect& content_rect, |
45 const gfx::Rect& source_rect, | 48 const gfx::Rect& source_rect, |
46 const gfx::Vector2d& dest_offset, | 49 const gfx::Vector2d& dest_offset, |
47 GLenum format, | 50 GLenum format, |
48 const gfx::Size& size); | 51 const gfx::Size& size); |
49 | 52 |
| 53 void flush(); |
| 54 |
50 private: | 55 private: |
51 class Query { | 56 class Query { |
52 public: | 57 public: |
53 static scoped_ptr<Query> create(WebKit::WebGraphicsContext3D* context) {
return make_scoped_ptr(new Query(context)); } | 58 static scoped_ptr<Query> create(WebKit::WebGraphicsContext3D* context) {
return make_scoped_ptr(new Query(context)); } |
54 | 59 |
55 virtual ~Query(); | 60 virtual ~Query(); |
56 | 61 |
57 void begin(); | 62 void begin(); |
58 void end(); | 63 void end(); |
59 bool isPending(); | 64 bool isPending(); |
60 unsigned value(); | 65 unsigned value(); |
61 size_t texturesUploaded(); | 66 size_t texturesUploaded(); |
62 void markAsNonBlocking(); | 67 void markAsNonBlocking(); |
63 bool isNonBlocking(); | 68 bool isNonBlocking(); |
64 | 69 |
65 private: | 70 private: |
66 explicit Query(WebKit::WebGraphicsContext3D*); | 71 explicit Query(WebKit::WebGraphicsContext3D*); |
67 | 72 |
68 WebKit::WebGraphicsContext3D* m_context; | 73 WebKit::WebGraphicsContext3D* m_context; |
69 unsigned m_queryId; | 74 unsigned m_queryId; |
70 unsigned m_value; | 75 unsigned m_value; |
71 bool m_hasValue; | 76 bool m_hasValue; |
72 bool m_isNonBlocking; | 77 bool m_isNonBlocking; |
73 }; | 78 }; |
74 | 79 |
75 TextureUploader(WebKit::WebGraphicsContext3D*, bool useMapTexSubImage); | 80 TextureUploader(WebKit::WebGraphicsContext3D*, |
| 81 bool useMapTexSubImage, |
| 82 bool useShallowFlush); |
76 | 83 |
77 void beginQuery(); | 84 void beginQuery(); |
78 void endQuery(); | 85 void endQuery(); |
79 void processQueries(); | 86 void processQueries(); |
80 | 87 |
81 void uploadWithTexSubImage(const uint8* image, | 88 void uploadWithTexSubImage(const uint8* image, |
82 const gfx::Rect& image_rect, | 89 const gfx::Rect& image_rect, |
83 const gfx::Rect& source_rect, | 90 const gfx::Rect& source_rect, |
84 const gfx::Vector2d& dest_offset, | 91 const gfx::Vector2d& dest_offset, |
85 GLenum format); | 92 GLenum format); |
86 void uploadWithMapTexSubImage(const uint8* image, | 93 void uploadWithMapTexSubImage(const uint8* image, |
87 const gfx::Rect& image_rect, | 94 const gfx::Rect& image_rect, |
88 const gfx::Rect& source_rect, | 95 const gfx::Rect& source_rect, |
89 const gfx::Vector2d& dest_offset, | 96 const gfx::Vector2d& dest_offset, |
90 GLenum format); | 97 GLenum format); |
91 | 98 |
92 WebKit::WebGraphicsContext3D* m_context; | 99 WebKit::WebGraphicsContext3D* m_context; |
93 ScopedPtrDeque<Query> m_pendingQueries; | 100 ScopedPtrDeque<Query> m_pendingQueries; |
94 ScopedPtrDeque<Query> m_availableQueries; | 101 ScopedPtrDeque<Query> m_availableQueries; |
95 std::multiset<double> m_texturesPerSecondHistory; | 102 std::multiset<double> m_texturesPerSecondHistory; |
96 size_t m_numBlockingTextureUploads; | 103 size_t m_numBlockingTextureUploads; |
97 | 104 |
98 bool m_useMapTexSubImage; | 105 bool m_useMapTexSubImage; |
99 size_t m_subImageSize; | 106 size_t m_subImageSize; |
100 scoped_array<uint8> m_subImage; | 107 scoped_array<uint8> m_subImage; |
101 | 108 |
| 109 bool m_useShallowFlush; |
| 110 size_t m_numTextureUploadsSinceLastFlush; |
| 111 |
102 DISALLOW_COPY_AND_ASSIGN(TextureUploader); | 112 DISALLOW_COPY_AND_ASSIGN(TextureUploader); |
103 }; | 113 }; |
104 | 114 |
105 } // namespace cc | 115 } // namespace cc |
106 | 116 |
107 #endif // CC_TEXTURE_UPLOADER_H_ | 117 #endif // CC_TEXTURE_UPLOADER_H_ |
OLD | NEW |