• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CC_SCHEDULER_TEXTURE_UPLOADER_H_
6 #define CC_SCHEDULER_TEXTURE_UPLOADER_H_
7 
8 #include <set>
9 
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"
15 
16 namespace gfx {
17 class Rect;
18 class Size;
19 class Vector2d;
20 }
21 
22 namespace gpu {
23 namespace gles2 {
24 class GLES2Interface;
25 }
26 }
27 
28 namespace cc {
29 
30 class CC_EXPORT TextureUploader {
31  public:
Create(gpu::gles2::GLES2Interface * gl)32   static scoped_ptr<TextureUploader> Create(gpu::gles2::GLES2Interface* gl) {
33     return make_scoped_ptr(new TextureUploader(gl));
34   }
35   ~TextureUploader();
36 
37   size_t NumBlockingUploads();
38   void MarkPendingUploadsAsNonBlocking();
39   double EstimatedTexturesPerSecond();
40 
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);
51 
52   void Flush();
53   void ReleaseCachedQueries();
54 
55  private:
56   class Query {
57    public:
Create(gpu::gles2::GLES2Interface * gl)58     static scoped_ptr<Query> Create(gpu::gles2::GLES2Interface* gl) {
59       return make_scoped_ptr(new Query(gl));
60     }
61 
62     virtual ~Query();
63 
64     void Begin();
65     void End();
66     bool IsPending();
67     unsigned Value();
68     size_t TexturesUploaded();
mark_as_non_blocking()69     void mark_as_non_blocking() {
70       is_non_blocking_ = true;
71     }
is_non_blocking()72     bool is_non_blocking() const {
73       return is_non_blocking_;
74     }
75 
76    private:
77     explicit Query(gpu::gles2::GLES2Interface* gl);
78 
79     gpu::gles2::GLES2Interface* gl_;
80     unsigned query_id_;
81     unsigned value_;
82     bool has_value_;
83     bool is_non_blocking_;
84 
85     DISALLOW_COPY_AND_ASSIGN(Query);
86   };
87 
88   explicit TextureUploader(gpu::gles2::GLES2Interface* gl);
89 
90   void BeginQuery();
91   void EndQuery();
92   void ProcessQueries();
93 
94   void UploadWithTexSubImage(const uint8* image,
95                              gfx::Rect image_rect,
96                              gfx::Rect source_rect,
97                              gfx::Vector2d dest_offset,
98                              ResourceFormat format);
99   void UploadWithMapTexSubImage(const uint8* image,
100                                 gfx::Rect image_rect,
101                                 gfx::Rect source_rect,
102                                 gfx::Vector2d dest_offset,
103                                 ResourceFormat format);
104   void UploadWithTexImageETC1(const uint8* image, gfx::Size size);
105 
106   gpu::gles2::GLES2Interface* gl_;
107   ScopedPtrDeque<Query> pending_queries_;
108   ScopedPtrDeque<Query> available_queries_;
109   std::multiset<double> textures_per_second_history_;
110   size_t num_blocking_texture_uploads_;
111 
112   size_t sub_image_size_;
113   scoped_ptr<uint8[]> sub_image_;
114 
115   size_t num_texture_uploads_since_last_flush_;
116 
117   DISALLOW_COPY_AND_ASSIGN(TextureUploader);
118 };
119 
120 }  // namespace cc
121 
122 #endif  // CC_SCHEDULER_TEXTURE_UPLOADER_H_
123