OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ | 5 #ifndef EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ |
6 #define EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ | 6 #define EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "mojo/public/c/gles2/gles2.h" | 11 #include "mojo/public/c/gles2/gles2.h" |
12 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" | 12 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" |
13 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" | 13 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
14 #include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" | 14 #include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" |
15 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 15 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
16 | 16 |
17 namespace mojo { | 17 namespace mojo { |
18 class Shell; | 18 class Shell; |
19 class View; | 19 class View; |
20 | 20 |
21 // BitmapUploader is useful if you want to draw a bitmap or color in a View. | 21 // BitmapUploader is useful if you want to draw a bitmap or color in a View. |
22 class BitmapUploader : public SurfaceClient { | 22 class BitmapUploader : public ResourceReturner { |
23 public: | 23 public: |
24 explicit BitmapUploader(View* view); | 24 explicit BitmapUploader(View* view); |
25 virtual ~BitmapUploader(); | 25 virtual ~BitmapUploader(); |
26 | 26 |
27 void Init(Shell* shell); | 27 void Init(Shell* shell); |
28 | 28 |
29 // Sets the color which is RGBA. | 29 // Sets the color which is RGBA. |
30 void SetColor(uint32_t color); | 30 void SetColor(uint32_t color); |
31 | 31 |
32 enum Format { | 32 enum Format { |
33 RGBA, // Pixel layout on Android. | 33 RGBA, // Pixel layout on Android. |
34 BGRA, // Pixel layout everywhere else. | 34 BGRA, // Pixel layout everywhere else. |
35 }; | 35 }; |
36 | 36 |
37 // Sets a bitmap. | 37 // Sets a bitmap. |
38 void SetBitmap(int width, | 38 void SetBitmap(int width, |
39 int height, | 39 int height, |
40 scoped_ptr<std::vector<unsigned char>> data, | 40 scoped_ptr<std::vector<unsigned char>> data, |
41 Format format); | 41 Format format); |
42 | 42 |
43 private: | 43 private: |
44 void Upload(); | 44 void Upload(); |
45 uint32_t BindTextureForSize(const Size size); | 45 uint32_t BindTextureForSize(const Size size); |
46 uint32_t TextureFormat(); | 46 uint32_t TextureFormat(); |
47 | 47 |
48 // SurfaceClient implementation. | 48 void SetIdNamespace(uint32_t id_namespace); |
49 void SetIdNamespace(uint32_t id_namespace) override; | 49 // ResourceReturner implementation. |
sky
2015/01/31 01:25:28
nit: newline between 48/49.
| |
50 void ReturnResources(Array<ReturnedResourcePtr> resources) override; | 50 void ReturnResources(Array<ReturnedResourcePtr> resources) override; |
51 | 51 |
52 View* view_; | 52 View* view_; |
53 GpuPtr gpu_service_; | 53 GpuPtr gpu_service_; |
54 MojoGLES2Context gles2_context_; | 54 MojoGLES2Context gles2_context_; |
55 | 55 |
56 Size size_; | 56 Size size_; |
57 uint32_t color_; | 57 uint32_t color_; |
58 int width_; | 58 int width_; |
59 int height_; | 59 int height_; |
60 Format format_; | 60 Format format_; |
61 scoped_ptr<std::vector<unsigned char>> bitmap_; | 61 scoped_ptr<std::vector<unsigned char>> bitmap_; |
62 SurfacePtr surface_; | 62 SurfacePtr surface_; |
63 Size surface_size_; | 63 Size surface_size_; |
64 uint32_t next_resource_id_; | 64 uint32_t next_resource_id_; |
65 uint32_t id_namespace_; | 65 uint32_t id_namespace_; |
66 uint32_t local_id_; | 66 uint32_t local_id_; |
67 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; | 67 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; |
68 mojo::Binding<mojo::ResourceReturner> returner_binding_; | |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); | 70 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); |
70 }; | 71 }; |
71 | 72 |
72 } // namespace mojo | 73 } // namespace mojo |
73 | 74 |
74 #endif // EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ | 75 #endif // EXAMPLES_BITMAP_UPLOADER_BITMAP_UPLOADER_H_ |
OLD | NEW |