Add entry to histograms.xml for OverlyLargeOriginLength.
[chromium-blink-merge.git] / cc / scheduler / texture_uploader.h
blob66e60c12aae573e883f4a01dc6cb5e88fa7191e7
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_SCHEDULER_TEXTURE_UPLOADER_H_
6 #define CC_SCHEDULER_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 blink { class WebGraphicsContext3D; }
18 namespace gfx {
19 class Rect;
20 class Size;
21 class Vector2d;
24 namespace cc {
26 class CC_EXPORT TextureUploader {
27 public:
28 static scoped_ptr<TextureUploader> Create(
29 blink::WebGraphicsContext3D* context,
30 bool use_map_tex_sub_image,
31 bool use_shallow_flush) {
32 return make_scoped_ptr(
33 new TextureUploader(context, use_map_tex_sub_image, use_shallow_flush));
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 gfx::Rect content_rect,
47 gfx::Rect source_rect,
48 gfx::Vector2d dest_offset,
49 ResourceFormat format,
50 gfx::Size size);
52 void Flush();
53 void ReleaseCachedQueries();
55 private:
56 class Query {
57 public:
58 static scoped_ptr<Query> Create(blink::WebGraphicsContext3D* context) {
59 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 mark_as_non_blocking() {
70 is_non_blocking_ = true;
72 bool is_non_blocking() const {
73 return is_non_blocking_;
76 private:
77 explicit Query(blink::WebGraphicsContext3D* context);
79 blink::WebGraphicsContext3D* context_;
80 unsigned query_id_;
81 unsigned value_;
82 bool has_value_;
83 bool is_non_blocking_;
85 DISALLOW_COPY_AND_ASSIGN(Query);
88 TextureUploader(blink::WebGraphicsContext3D* context,
89 bool use_map_tex_sub_image,
90 bool use_shallow_flush);
92 void BeginQuery();
93 void EndQuery();
94 void ProcessQueries();
96 void UploadWithTexSubImage(const uint8* image,
97 gfx::Rect image_rect,
98 gfx::Rect source_rect,
99 gfx::Vector2d dest_offset,
100 ResourceFormat format);
101 void UploadWithMapTexSubImage(const uint8* image,
102 gfx::Rect image_rect,
103 gfx::Rect source_rect,
104 gfx::Vector2d dest_offset,
105 ResourceFormat format);
106 void UploadWithTexImageETC1(const uint8* image, gfx::Size size);
108 blink::WebGraphicsContext3D* context_;
109 ScopedPtrDeque<Query> pending_queries_;
110 ScopedPtrDeque<Query> available_queries_;
111 std::multiset<double> textures_per_second_history_;
112 size_t num_blocking_texture_uploads_;
114 bool use_map_tex_sub_image_;
115 size_t sub_image_size_;
116 scoped_ptr<uint8[]> sub_image_;
118 bool use_shallow_flush_;
119 size_t num_texture_uploads_since_last_flush_;
121 DISALLOW_COPY_AND_ASSIGN(TextureUploader);
124 } // namespace cc
126 #endif // CC_SCHEDULER_TEXTURE_UPLOADER_H_