OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 WM_GPU_FOREIGN_WINDOW_TEXTURE_FACTORY_H_ | |
6 #define WM_GPU_FOREIGN_WINDOW_TEXTURE_FACTORY_H_ | |
7 | |
8 #include "base/bind.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "content/browser/renderer_host/image_transport_factory.h" | |
11 #include "ui/compositor/compositor.h" | |
12 #include "ui/gfx/native_widget_types.h" | |
13 | |
14 namespace content { | |
15 class GpuChannelHostFactory; | |
16 }; | |
17 | |
18 namespace wm { | |
19 | |
20 // This class provides a way to get notified when textures get lost. | |
21 class ForeignWindowTextureFactoryObserver { | |
22 public: | |
23 virtual ~ForeignWindowTextureFactoryObserver() {} | |
24 | |
25 // Notifies that the textures generated by ForeignWindowTextureFactory were | |
26 // lost. | |
27 virtual void OnLostResources() = 0; | |
28 }; | |
29 | |
30 // This class provides the interface for notifying the texture implementation | |
31 // that contents has changed. | |
32 class ForeignWindowTexture : | |
33 public ui::Texture, | |
34 public ForeignWindowTextureFactoryObserver { | |
35 public: | |
36 // ui::Texture overrides: | |
37 virtual unsigned int PrepareTexture() OVERRIDE; | |
38 virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE; | |
39 | |
40 // ForeignWindowTextureFactoryObserver overrides: | |
41 virtual void OnLostResources() OVERRIDE; | |
42 | |
43 // Indicate that native window contents have changed. | |
44 void OnContentsChanged(); | |
45 | |
46 protected: | |
47 virtual ~ForeignWindowTexture(); | |
48 | |
49 private: | |
50 friend class ForeignWindowTextureFactory; | |
51 | |
52 ForeignWindowTexture(content::GpuChannelHostFactory* factory, | |
53 WebKit::WebGraphicsContext3D* host_context, | |
54 bool flipped, | |
55 const gfx::Size& size, | |
56 float device_scale_factor, | |
57 int32 image_id); | |
58 | |
59 content::GpuChannelHostFactory* factory_; | |
60 WebKit::WebGraphicsContext3D* host_context_; | |
61 int32 image_id_; | |
62 unsigned texture_id_; | |
63 bool contents_changed_; | |
64 }; | |
65 | |
66 // This class provides the interface for creating textures boudn to native | |
danakj
2013/02/21 01:33:15
"bound"
bound to a foreign window, no?
reveman
2013/02/22 01:26:44
Done.
| |
67 // windows. The factory is a process-wide singleton. | |
68 class ForeignWindowTextureFactory | |
69 : public content::ImageTransportFactoryObserver { | |
70 public: | |
71 typedef base::Callback<void(scoped_refptr<ForeignWindowTexture>)> | |
72 CreateTextureCallback; | |
73 | |
74 // Initialize the global texture factory. | |
75 static void Initialize(); | |
76 | |
77 // Terminates the global texture factory. | |
78 static void Terminate(); | |
79 | |
80 // Gets the factory instance. | |
81 static ForeignWindowTextureFactory* GetInstance(); | |
82 | |
83 // ImageTransportFactoryObserver overrides: | |
84 virtual void OnLostResources() OVERRIDE; | |
85 | |
86 // Create a texture from a native window. | |
87 void CreateTextureForForeignWindow( | |
88 gfx::PluginWindowHandle window, | |
89 bool flipped, | |
90 float device_scale_factor, | |
91 const CreateTextureCallback& callback); | |
92 | |
93 void AddObserver(ForeignWindowTextureFactoryObserver* observer); | |
94 void RemoveObserver(ForeignWindowTextureFactoryObserver* observer); | |
95 | |
96 private: | |
97 explicit ForeignWindowTextureFactory( | |
98 content::GpuChannelHostFactory* factory); | |
99 virtual ~ForeignWindowTextureFactory(); | |
100 | |
101 int GenerateImageID(); | |
102 | |
103 void OnImageCreated(const CreateTextureCallback& callback, | |
104 bool flipped, | |
105 float device_scale_factor, | |
106 int32 image_id, | |
107 const gfx::Size size); | |
108 | |
109 static ForeignWindowTextureFactory* instance_; | |
110 | |
111 content::GpuChannelHostFactory* factory_; | |
112 | |
113 ObserverList<ForeignWindowTextureFactoryObserver> observer_list_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(ForeignWindowTextureFactory); | |
116 }; | |
117 | |
118 } // namespace wm | |
119 | |
120 #endif // WM_GPU_FOREIGN_WINDOW_TEXTURE_FACTORY_H_ | |
OLD | NEW |