OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ | 5 #ifndef SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ |
6 #define SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ | 6 #define SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
15 #include "gpu/GLES2/gl2chromium.h" | 16 #include "gpu/GLES2/gl2chromium.h" |
16 #include "gpu/GLES2/gl2extchromium.h" | 17 #include "gpu/GLES2/gl2extchromium.h" |
17 #include "services/ui/public/cpp/window_surface.h" | 18 #include "services/ui/public/cpp/window_surface.h" |
18 #include "services/ui/public/cpp/window_surface_client.h" | 19 #include "services/ui/public/cpp/window_surface_client.h" |
19 #include "services/ui/public/interfaces/surface.mojom.h" | 20 #include "services/ui/public/interfaces/surface.mojom.h" |
20 | 21 |
| 22 namespace gpu { |
| 23 class GpuChannelHost; |
| 24 } |
| 25 |
21 namespace ui { | 26 namespace ui { |
22 class GLES2Context; | 27 class GLES2Context; |
23 class GpuService; | 28 class GpuService; |
24 | 29 |
25 extern const char kBitmapUploaderForAcceleratedWidget[]; | 30 extern const char kBitmapUploaderForAcceleratedWidget[]; |
26 | 31 |
27 // BitmapUploader is useful if you want to draw a bitmap or color in a | 32 // BitmapUploader is useful if you want to draw a bitmap or color in a |
28 // Window. | 33 // Window. |
29 class BitmapUploader : public WindowSurfaceClient { | 34 class BitmapUploader : public WindowSurfaceClient { |
30 public: | 35 public: |
(...skipping 11 matching lines...) Expand all Loading... |
42 | 47 |
43 // Sets a bitmap. | 48 // Sets a bitmap. |
44 void SetBitmap(int width, | 49 void SetBitmap(int width, |
45 int height, | 50 int height, |
46 std::unique_ptr<std::vector<unsigned char>> data, | 51 std::unique_ptr<std::vector<unsigned char>> data, |
47 Format format); | 52 Format format); |
48 | 53 |
49 private: | 54 private: |
50 void Upload(); | 55 void Upload(); |
51 | 56 |
| 57 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
| 58 |
52 uint32_t BindTextureForSize(const gfx::Size& size); | 59 uint32_t BindTextureForSize(const gfx::Size& size); |
53 | 60 |
54 uint32_t TextureFormat() const { | 61 uint32_t TextureFormat() const { |
55 return format_ == BGRA ? GL_BGRA_EXT : GL_RGBA; | 62 return format_ == BGRA ? GL_BGRA_EXT : GL_RGBA; |
56 } | 63 } |
57 | 64 |
58 void SetIdNamespace(uint32_t id_namespace); | 65 void SetIdNamespace(uint32_t id_namespace); |
59 | 66 |
60 // WindowSurfaceClient implementation. | 67 // WindowSurfaceClient implementation. |
61 void OnResourcesReturned(WindowSurface* surface, | 68 void OnResourcesReturned(WindowSurface* surface, |
62 const cc::ReturnedResourceArray& resources) override; | 69 const cc::ReturnedResourceArray& resources) override; |
63 | 70 |
64 Window* window_; | 71 Window* window_; |
65 std::unique_ptr<WindowSurface> surface_; | 72 std::unique_ptr<WindowSurface> surface_; |
66 // This may be null if there is an error contacting mus/initializing. We | 73 // This may be null if there is an error contacting mus/initializing. We |
67 // assume we'll be shutting down soon and do nothing in this case. | 74 // assume we'll be shutting down soon and do nothing in this case. |
68 std::unique_ptr<GLES2Context> gles2_context_; | 75 std::unique_ptr<GLES2Context> gles2_context_; |
69 | 76 |
70 uint32_t color_; | 77 uint32_t color_; |
71 int width_; | 78 int width_; |
72 int height_; | 79 int height_; |
73 Format format_; | 80 Format format_; |
74 std::unique_ptr<std::vector<unsigned char>> bitmap_; | 81 std::unique_ptr<std::vector<unsigned char>> bitmap_; |
75 uint32_t next_resource_id_; | 82 uint32_t next_resource_id_; |
76 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; | 83 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; |
77 | 84 |
| 85 base::WeakPtrFactory<BitmapUploader> weak_factory_; |
| 86 |
78 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); | 87 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); |
79 }; | 88 }; |
80 | 89 |
81 } // namespace ui | 90 } // namespace ui |
82 | 91 |
83 #endif // SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ | 92 #endif // SERVICES_UI_DEMO_BITMAP_UPLOADER_H_ |
OLD | NEW |