Depend on stored sync session GUID for Android.
[chromium-blink-merge.git] / cc / texture_uploader.h
blobdecdbda68520e877a6b57bc5ceb86f1c6109fa4b
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_
8 #include <set>
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"
16 namespace WebKit {
17 class WebGraphicsContext3D;
20 namespace gfx {
21 class Rect;
22 class Size;
23 class Vector2d;
26 namespace cc {
28 class CC_EXPORT TextureUploader {
29 public:
30 static scoped_ptr<TextureUploader> create(
31 WebKit::WebGraphicsContext3D* context,
32 bool useMapTexSubImage,
33 bool useShallowFlush)
35 return make_scoped_ptr(
36 new TextureUploader(context, useMapTexSubImage, useShallowFlush));
38 ~TextureUploader();
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,
52 GLenum format,
53 const gfx::Size& size);
55 void flush();
57 private:
58 class Query {
59 public:
60 static scoped_ptr<Query> create(WebKit::WebGraphicsContext3D* context) { return make_scoped_ptr(new Query(context)); }
62 virtual ~Query();
64 void begin();
65 void end();
66 bool isPending();
67 unsigned value();
68 size_t texturesUploaded();
69 void markAsNonBlocking();
70 bool isNonBlocking();
72 private:
73 explicit Query(WebKit::WebGraphicsContext3D*);
75 WebKit::WebGraphicsContext3D* m_context;
76 unsigned m_queryId;
77 unsigned m_value;
78 bool m_hasValue;
79 bool m_isNonBlocking;
82 TextureUploader(WebKit::WebGraphicsContext3D*,
83 bool useMapTexSubImage,
84 bool useShallowFlush);
86 void beginQuery();
87 void endQuery();
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,
94 GLenum format);
95 void uploadWithMapTexSubImage(const uint8* image,
96 const gfx::Rect& image_rect,
97 const gfx::Rect& source_rect,
98 const gfx::Vector2d& dest_offset,
99 GLenum format);
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);
117 } // namespace cc
119 #endif // CC_TEXTURE_UPLOADER_H_