OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 COMPONENTS_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ | |
6 #define COMPONENTS_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/compiler_specific.h" | |
13 #include "base/containers/hash_tables.h" | |
14 #include "base/macros.h" | |
15 #include "components/bitmap_uploader/bitmap_uploader_export.h" | |
16 #include "gpu/GLES2/gl2chromium.h" | |
17 #include "gpu/GLES2/gl2extchromium.h" | |
18 #include "services/ui/public/cpp/window_surface.h" | |
19 #include "services/ui/public/cpp/window_surface_client.h" | |
20 #include "services/ui/public/interfaces/surface.mojom.h" | |
21 | |
22 namespace ui { | |
23 class GLES2Context; | |
24 } | |
25 | |
26 namespace shell { | |
27 class Connector; | |
28 } | |
29 | |
30 namespace bitmap_uploader { | |
31 | |
32 BITMAP_UPLOADER_EXPORT extern const char kBitmapUploaderForAcceleratedWidget[]; | |
33 | |
34 // BitmapUploader is useful if you want to draw a bitmap or color in a | |
35 // ui::Window. | |
36 class BITMAP_UPLOADER_EXPORT BitmapUploader | |
37 : public NON_EXPORTED_BASE(ui::WindowSurfaceClient) { | |
38 public: | |
39 explicit BitmapUploader(ui::Window* window); | |
40 ~BitmapUploader() override; | |
41 | |
42 void Init(shell::Connector* connector); | |
43 | |
44 // Sets the color which is RGBA. | |
45 void SetColor(uint32_t color); | |
46 | |
47 enum Format { | |
48 RGBA, // Pixel layout on Android. | |
49 BGRA, // Pixel layout everywhere else. | |
50 }; | |
51 | |
52 // Sets a bitmap. | |
53 void SetBitmap(int width, | |
54 int height, | |
55 std::unique_ptr<std::vector<unsigned char>> data, | |
56 Format format); | |
57 | |
58 private: | |
59 void Upload(); | |
60 | |
61 uint32_t BindTextureForSize(const gfx::Size& size); | |
62 | |
63 uint32_t TextureFormat() const { | |
64 return format_ == BGRA ? GL_BGRA_EXT : GL_RGBA; | |
65 } | |
66 | |
67 void SetIdNamespace(uint32_t id_namespace); | |
68 | |
69 // WindowSurfaceClient implementation. | |
70 void OnResourcesReturned( | |
71 ui::WindowSurface* surface, | |
72 mojo::Array<cc::ReturnedResource> resources) override; | |
73 | |
74 ui::Window* window_; | |
75 std::unique_ptr<ui::WindowSurface> surface_; | |
76 // This may be null if there is an error contacting mus/initializing. We | |
77 // assume we'll be shutting down soon and do nothing in this case. | |
78 std::unique_ptr<ui::GLES2Context> gles2_context_; | |
79 | |
80 uint32_t color_; | |
81 int width_; | |
82 int height_; | |
83 Format format_; | |
84 std::unique_ptr<std::vector<unsigned char>> bitmap_; | |
85 uint32_t next_resource_id_; | |
86 uint32_t id_namespace_; | |
87 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); | |
90 }; | |
91 | |
92 } // namespace bitmap_uploader | |
93 | |
94 #endif // COMPONENTS_BITMAP_UPLOADER_BITMAP_UPLAODER_H_ | |
OLD | NEW |