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