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
3 // found in the LICENSE file.
5 #ifndef CC_TEXTURE_UPLOADER_H_
6 #define CC_TEXTURE_UPLOADER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/cc_export.h"
13 #include "cc/scoped_ptr_deque.h"
14 #include "third_party/khronos/GLES2/gl2.h"
17 class WebGraphicsContext3D
;
28 class CC_EXPORT TextureUploader
{
30 static scoped_ptr
<TextureUploader
> create(
31 WebKit::WebGraphicsContext3D
* context
,
32 bool useMapTexSubImage
,
35 return make_scoped_ptr(
36 new TextureUploader(context
, useMapTexSubImage
, useShallowFlush
));
40 size_t numBlockingUploads();
41 void markPendingUploadsAsNonBlocking();
42 double estimatedTexturesPerSecond();
44 // Let imageRect be a rectangle, and let sourceRect be a sub-rectangle of
45 // imageRect, expressed in the same coordinate system as imageRect. Let
46 // image be a buffer for imageRect. This function will copy the region
47 // corresponding to sourceRect to destOffset in this sub-image.
48 void upload(const uint8
* image
,
49 const gfx::Rect
& content_rect
,
50 const gfx::Rect
& source_rect
,
51 const gfx::Vector2d
& dest_offset
,
53 const gfx::Size
& size
);
60 static scoped_ptr
<Query
> create(WebKit::WebGraphicsContext3D
* context
) { return make_scoped_ptr(new Query(context
)); }
68 size_t texturesUploaded();
69 void markAsNonBlocking();
73 explicit Query(WebKit::WebGraphicsContext3D
*);
75 WebKit::WebGraphicsContext3D
* m_context
;
82 TextureUploader(WebKit::WebGraphicsContext3D
*,
83 bool useMapTexSubImage
,
84 bool useShallowFlush
);
88 void processQueries();
90 void uploadWithTexSubImage(const uint8
* image
,
91 const gfx::Rect
& image_rect
,
92 const gfx::Rect
& source_rect
,
93 const gfx::Vector2d
& dest_offset
,
95 void uploadWithMapTexSubImage(const uint8
* image
,
96 const gfx::Rect
& image_rect
,
97 const gfx::Rect
& source_rect
,
98 const gfx::Vector2d
& dest_offset
,
101 WebKit::WebGraphicsContext3D
* m_context
;
102 ScopedPtrDeque
<Query
> m_pendingQueries
;
103 ScopedPtrDeque
<Query
> m_availableQueries
;
104 std::multiset
<double> m_texturesPerSecondHistory
;
105 size_t m_numBlockingTextureUploads
;
107 bool m_useMapTexSubImage
;
108 size_t m_subImageSize
;
109 scoped_array
<uint8
> m_subImage
;
111 bool m_useShallowFlush
;
112 size_t m_numTextureUploadsSinceLastFlush
;
114 DISALLOW_COPY_AND_ASSIGN(TextureUploader
);
119 #endif // CC_TEXTURE_UPLOADER_H_