Update extension docs for options V2 to mention chrome.runtime.openOptionsPage.
[chromium-blink-merge.git] / cc / resources / texture_uploader.h
blob72c46e7ffb5dc4013151941bb3aa2cebc83549f9
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.
5 #ifndef CC_RESOURCES_TEXTURE_UPLOADER_H_
6 #define CC_RESOURCES_TEXTURE_UPLOADER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/base/scoped_ptr_deque.h"
14 #include "cc/resources/resource_provider.h"
16 namespace gfx {
17 class Rect;
18 class Size;
19 class Vector2d;
22 namespace gpu {
23 namespace gles2 {
24 class GLES2Interface;
28 namespace cc {
30 class CC_EXPORT TextureUploader {
31 public:
32 static scoped_ptr<TextureUploader> Create(gpu::gles2::GLES2Interface* gl) {
33 return make_scoped_ptr(new TextureUploader(gl));
35 ~TextureUploader();
37 size_t NumBlockingUploads();
38 void MarkPendingUploadsAsNonBlocking();
39 double EstimatedTexturesPerSecond();
41 // Let content_rect be a rectangle, and let content_rect be a sub-rectangle of
42 // content_rect, expressed in the same coordinate system as content_rect. Let
43 // image be a buffer for content_rect. This function will copy the region
44 // corresponding to source_rect to dest_offset in this sub-image.
45 void Upload(const uint8* image,
46 const gfx::Rect& content_rect,
47 const gfx::Rect& source_rect,
48 gfx::Vector2d dest_offset,
49 ResourceFormat format,
50 const gfx::Size& size);
52 void Flush();
53 void ReleaseCachedQueries();
55 private:
56 class Query {
57 public:
58 static scoped_ptr<Query> Create(gpu::gles2::GLES2Interface* gl) {
59 return make_scoped_ptr(new Query(gl));
62 virtual ~Query();
64 void Begin();
65 void End();
66 bool IsPending();
67 unsigned Value();
68 size_t TexturesUploaded();
69 void mark_as_non_blocking() { is_non_blocking_ = true; }
70 bool is_non_blocking() const { return is_non_blocking_; }
72 private:
73 explicit Query(gpu::gles2::GLES2Interface* gl);
75 gpu::gles2::GLES2Interface* gl_;
76 unsigned query_id_;
77 unsigned value_;
78 bool has_value_;
79 bool is_non_blocking_;
81 DISALLOW_COPY_AND_ASSIGN(Query);
84 explicit TextureUploader(gpu::gles2::GLES2Interface* gl);
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 gfx::Vector2d dest_offset,
94 ResourceFormat format);
95 void UploadWithMapTexSubImage(const uint8* image,
96 const gfx::Rect& image_rect,
97 const gfx::Rect& source_rect,
98 gfx::Vector2d dest_offset,
99 ResourceFormat format);
100 void UploadWithTexImageETC1(const uint8* image, const gfx::Size& size);
102 gpu::gles2::GLES2Interface* gl_;
103 ScopedPtrDeque<Query> pending_queries_;
104 ScopedPtrDeque<Query> available_queries_;
105 std::multiset<double> textures_per_second_history_;
106 size_t num_blocking_texture_uploads_;
108 size_t sub_image_size_;
109 scoped_ptr<uint8[]> sub_image_;
111 size_t num_texture_uploads_since_last_flush_;
113 DISALLOW_COPY_AND_ASSIGN(TextureUploader);
116 } // namespace cc
118 #endif // CC_RESOURCES_TEXTURE_UPLOADER_H_