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

Side by Side Diff: ui/gl/gl_surface.h

Issue 1652873002: Android: Use virtualized context only for those with compatible config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment addressed Created 4 years, 10 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 UI_GL_GL_SURFACE_H_ 5 #ifndef UI_GL_GL_SURFACE_H_
6 #define UI_GL_GL_SURFACE_H_ 6 #define UI_GL_GL_SURFACE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/sys_info.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/rect_f.h" 16 #include "ui/gfx/geometry/rect_f.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/overlay_transform.h" 19 #include "ui/gfx/overlay_transform.h"
19 #include "ui/gfx/swap_result.h" 20 #include "ui/gfx/swap_result.h"
20 #include "ui/gl/gl_export.h" 21 #include "ui/gl/gl_export.h"
21 #include "ui/gl/gl_implementation.h" 22 #include "ui/gl/gl_implementation.h"
22 23
23 namespace gl { 24 namespace gl {
24 class GLImage; 25 class GLImage;
25 } 26 }
26 27
27 namespace gfx { 28 namespace gfx {
28 29
29 class GLContext; 30 class GLContext;
30 class Transform; 31 class Transform;
31 class VSyncProvider; 32 class VSyncProvider;
32 33
33 // Encapsulates a surface that can be rendered to with GL, hiding platform 34 // Encapsulates a surface that can be rendered to with GL, hiding platform
34 // specific management. 35 // specific management.
35 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { 36 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> {
36 public: 37 public:
37 GLSurface(); 38 GLSurface();
38 39
39 // Minimum bit depth of surface. 40 // Minimum bit depth of surface.
40 enum Format { 41 enum Format {
41 SURFACE_ARGB8888 = 1, // 32 bits 42 SURFACE_ARGB8888,
42 SURFACE_RGB565 = 2, // 16 bits 43 SURFACE_RGB565,
43 SURFACE_DEFAULT = SURFACE_ARGB8888 44 SURFACE_DEFAULT = SURFACE_ARGB8888
44 }; 45 };
45 46
46 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the 47 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the
47 // EGL surface associated to be recreated without destroying the associated 48 // EGL surface associated to be recreated without destroying the associated
48 // context. The implementation of this function for other GLSurface derived 49 // context. The implementation of this function for other GLSurface derived
49 // classes is in a pending changelist. 50 // classes is in a pending changelist.
50 virtual bool Initialize(); 51 virtual bool Initialize();
51 virtual bool Initialize(GLSurface::Format format); 52 virtual bool Initialize(GLSurface::Format format);
52 53
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 virtual void* GetShareHandle(); 146 virtual void* GetShareHandle();
146 147
147 // Get the platform specific display on which this surface resides, if 148 // Get the platform specific display on which this surface resides, if
148 // available. 149 // available.
149 virtual void* GetDisplay(); 150 virtual void* GetDisplay();
150 151
151 // Get the platfrom specific configuration for this surface, if available. 152 // Get the platfrom specific configuration for this surface, if available.
152 virtual void* GetConfig(); 153 virtual void* GetConfig();
153 154
154 // Get the GL pixel format of the surface, if available. 155 // Get the GL pixel format of the surface, if available.
155 virtual unsigned GetFormat(); 156 virtual GLSurface::Format GetFormat();
156 157
157 // Get access to a helper providing time of recent refresh and period 158 // Get access to a helper providing time of recent refresh and period
158 // of screen refresh. If unavailable, returns NULL. 159 // of screen refresh. If unavailable, returns NULL.
159 virtual VSyncProvider* GetVSyncProvider(); 160 virtual VSyncProvider* GetVSyncProvider();
160 161
161 // Schedule an overlay plane to be shown at swap time, or on the next 162 // Schedule an overlay plane to be shown at swap time, or on the next
162 // CommitOverlayPlanes call. 163 // CommitOverlayPlanes call.
163 // |z_order| specifies the stacking order of the plane relative to the 164 // |z_order| specifies the stacking order of the plane relative to the
164 // main framebuffer located at index 0. For the case where there is no 165 // main framebuffer located at index 0. For the case where there is no
165 // main framebuffer, overlays may be scheduled at 0, taking its place. 166 // main framebuffer, overlays may be scheduled at 0, taking its place.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 203
203 #if defined(USE_OZONE) 204 #if defined(USE_OZONE)
204 // Create a GL surface that renders directly into a window with surfaceless 205 // Create a GL surface that renders directly into a window with surfaceless
205 // semantics - there is no default framebuffer and the primary surface must 206 // semantics - there is no default framebuffer and the primary surface must
206 // be presented as an overlay. If surfaceless mode is not supported or 207 // be presented as an overlay. If surfaceless mode is not supported or
207 // enabled it will return a null pointer. 208 // enabled it will return a null pointer.
208 static scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( 209 static scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface(
209 gfx::AcceleratedWidget window); 210 gfx::AcceleratedWidget window);
210 #endif // defined(USE_OZONE) 211 #endif // defined(USE_OZONE)
211 212
213 static Format GetDefaultFormat() {
214 return base::SysInfo::IsLowEndDevice() ? SURFACE_RGB565 : SURFACE_ARGB8888;
no sievers 2016/02/17 23:38:01 Can you make this logic/format override specific t
Jinsuk Kim 2016/02/18 02:57:24 Done.
215 }
216
212 // Create a GL surface used for offscreen rendering. 217 // Create a GL surface used for offscreen rendering.
213 static scoped_refptr<GLSurface> CreateOffscreenGLSurface( 218 static scoped_refptr<GLSurface> CreateOffscreenGLSurface(
214 const gfx::Size& size) { 219 const gfx::Size& size) {
215 return CreateOffscreenGLSurface(size, SURFACE_DEFAULT); 220 return CreateOffscreenGLSurface(size, GetDefaultFormat());
216 } 221 }
217 222
218 static scoped_refptr<GLSurface> CreateOffscreenGLSurface( 223 static scoped_refptr<GLSurface> CreateOffscreenGLSurface(
219 const gfx::Size& size, GLSurface::Format format); 224 const gfx::Size& size, GLSurface::Format format);
220 225
221 static GLSurface* GetCurrent(); 226 static GLSurface* GetCurrent();
222 227
223 // Called when the swap interval for the associated context changes. 228 // Called when the swap interval for the associated context changes.
224 virtual void OnSetSwapInterval(int interval); 229 virtual void OnSetSwapInterval(int interval);
225 230
226 protected: 231 protected:
227 virtual ~GLSurface(); 232 virtual ~GLSurface();
228 static bool InitializeOneOffImplementation(GLImplementation impl, 233 static bool InitializeOneOffImplementation(GLImplementation impl,
229 bool fallback_to_osmesa, 234 bool fallback_to_osmesa,
230 bool gpu_service_logging, 235 bool gpu_service_logging,
231 bool disable_gl_drawing); 236 bool disable_gl_drawing);
232 static bool InitializeOneOffInternal(); 237 static bool InitializeOneOffInternal();
233 static void SetCurrent(GLSurface* surface); 238 static void SetCurrent(GLSurface* surface);
234 239
235 static bool ExtensionsContain(const char* extensions, const char* name); 240 static bool ExtensionsContain(const char* extensions, const char* name);
236 241
242 GLSurface::Format format_;
243
237 private: 244 private:
238 friend class base::RefCounted<GLSurface>; 245 friend class base::RefCounted<GLSurface>;
239 friend class GLContext; 246 friend class GLContext;
240 friend class GLSurfaceTestSupport; 247 friend class GLSurfaceTestSupport;
241 248
242 DISALLOW_COPY_AND_ASSIGN(GLSurface); 249 DISALLOW_COPY_AND_ASSIGN(GLSurface);
243 }; 250 };
244 251
245 // Implementation of GLSurface that forwards all calls through to another 252 // Implementation of GLSurface that forwards all calls through to another
246 // GLSurface. 253 // GLSurface.
(...skipping 25 matching lines...) Expand all
272 bool SupportsAsyncSwap() override; 279 bool SupportsAsyncSwap() override;
273 gfx::Size GetSize() override; 280 gfx::Size GetSize() override;
274 void* GetHandle() override; 281 void* GetHandle() override;
275 unsigned int GetBackingFrameBufferObject() override; 282 unsigned int GetBackingFrameBufferObject() override;
276 bool OnMakeCurrent(GLContext* context) override; 283 bool OnMakeCurrent(GLContext* context) override;
277 bool SetBackbufferAllocation(bool allocated) override; 284 bool SetBackbufferAllocation(bool allocated) override;
278 void SetFrontbufferAllocation(bool allocated) override; 285 void SetFrontbufferAllocation(bool allocated) override;
279 void* GetShareHandle() override; 286 void* GetShareHandle() override;
280 void* GetDisplay() override; 287 void* GetDisplay() override;
281 void* GetConfig() override; 288 void* GetConfig() override;
282 unsigned GetFormat() override; 289 GLSurface::Format GetFormat() override;
283 VSyncProvider* GetVSyncProvider() override; 290 VSyncProvider* GetVSyncProvider() override;
284 bool ScheduleOverlayPlane(int z_order, 291 bool ScheduleOverlayPlane(int z_order,
285 OverlayTransform transform, 292 OverlayTransform transform,
286 gl::GLImage* image, 293 gl::GLImage* image,
287 const Rect& bounds_rect, 294 const Rect& bounds_rect,
288 const RectF& crop_rect) override; 295 const RectF& crop_rect) override;
289 bool IsSurfaceless() const override; 296 bool IsSurfaceless() const override;
290 bool FlipsVertically() const override; 297 bool FlipsVertically() const override;
291 bool BuffersFlipped() const override; 298 bool BuffersFlipped() const override;
292 299
293 GLSurface* surface() const { return surface_.get(); } 300 GLSurface* surface() const { return surface_.get(); }
294 301
295 protected: 302 protected:
296 ~GLSurfaceAdapter() override; 303 ~GLSurfaceAdapter() override;
297 304
298 private: 305 private:
299 scoped_refptr<GLSurface> surface_; 306 scoped_refptr<GLSurface> surface_;
300 307
301 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter); 308 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter);
302 }; 309 };
303 310
304 } // namespace gfx 311 } // namespace gfx
305 312
306 #endif // UI_GL_GL_SURFACE_H_ 313 #endif // UI_GL_GL_SURFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698