Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: services/ui/demo/bitmap_uploader.h

Issue 2551733002: Converting Mus Demo to use Aura. (Closed)
Patch Set: Addressing feedback. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_DEMO_BITMAP_UPLOADER_H_
6 #define SERVICES_UI_DEMO_BITMAP_UPLOADER_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <unordered_map>
12
13 #include "base/compiler_specific.h"
14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h"
16 #include "cc/output/compositor_frame_sink_client.h"
17 #include "gpu/GLES2/gl2chromium.h"
18 #include "gpu/GLES2/gl2extchromium.h"
19 #include "services/ui/public/cpp/window_compositor_frame_sink.h"
20
21 namespace gpu {
22 class GpuChannelHost;
23 }
24
25 namespace ui {
26
27 class GpuService;
28 class Window;
29
30 extern const char kBitmapUploaderForAcceleratedWidget[];
31
32 // BitmapUploader is useful if you want to draw a bitmap or color in a
33 // Window.
34 class BitmapUploader : public cc::CompositorFrameSinkClient {
35 public:
36 explicit BitmapUploader(Window* window);
37 ~BitmapUploader() override;
38
39 void Init(GpuService* gpu_service);
40 // Sets the color which is RGBA.
41 void SetColor(uint32_t color);
42
43 enum Format {
44 RGBA, // Pixel layout on Android.
45 BGRA, // Pixel layout everywhere else.
46 };
47
48 // Sets a bitmap.
49 void SetBitmap(int width,
50 int height,
51 std::unique_ptr<std::vector<unsigned char>> data,
52 Format format);
53
54 private:
55 void Upload();
56
57 void OnGpuChannelEstablished(
58 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
59 scoped_refptr<gpu::GpuChannelHost> gpu_channel);
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 // cc::CompositorFrameSinkClient implementation.
70 void SetBeginFrameSource(cc::BeginFrameSource* source) override;
71 void ReclaimResources(const cc::ReturnedResourceArray& resources) override;
72 void SetTreeActivationCallback(const base::Closure& callback) override;
73 void DidReceiveCompositorFrameAck() override;
74 void DidLoseCompositorFrameSink() override;
75 void OnDraw(const gfx::Transform& transform,
76 const gfx::Rect& viewport,
77 bool resourceless_software_draw) override;
78 void SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) override;
79 void SetExternalTilePriorityConstraints(
80 const gfx::Rect& viewport_rect,
81 const gfx::Transform& transform) override;
82
83 Window* window_;
84 std::unique_ptr<WindowCompositorFrameSink> compositor_frame_sink_;
85
86 uint32_t color_;
87 int width_;
88 int height_;
89 Format format_;
90 std::unique_ptr<std::vector<unsigned char>> bitmap_;
91 uint32_t next_resource_id_;
92 std::unordered_map<uint32_t, uint32_t> resource_to_texture_id_map_;
93
94 base::WeakPtrFactory<BitmapUploader> weak_factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(BitmapUploader);
97 };
98
99 } // namespace ui
100
101 #endif // SERVICES_UI_DEMO_BITMAP_UPLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698