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 GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_
6#define GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_
7
8#include "base/callback.h"
9#include "base/compiler_specific.h"
10#include "gl_in_process_context_export.h"
11#include "gpu/command_buffer/common/gles2_cmd_utils.h"
12#include "gpu/command_buffer/service/in_process_command_buffer.h"
13#include "ui/gfx/native_widget_types.h"
14#include "ui/gl/gl_surface.h"
15#include "ui/gl/gpu_preference.h"
16
17namespace gfx {
18class Size;
19}
20
21#if defined(OS_ANDROID)
22namespace gfx {
23class SurfaceTexture;
24}
25#endif
26
27namespace gpu {
28
29namespace gles2 {
30class GLES2Implementation;
31}
32
33struct GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContextSharedMemoryLimits {
34  GLInProcessContextSharedMemoryLimits();
35
36  int32 command_buffer_size;
37  unsigned int start_transfer_buffer_size;
38  unsigned int min_transfer_buffer_size;
39  unsigned int max_transfer_buffer_size;
40  unsigned int mapped_memory_reclaim_limit;
41};
42
43class GL_IN_PROCESS_CONTEXT_EXPORT GLInProcessContext {
44 public:
45  virtual ~GLInProcessContext() {}
46
47  // Create a GLInProcessContext, if |is_offscreen| is true, renders to an
48  // offscreen context. |attrib_list| must be NULL or a NONE-terminated list
49  // of attribute/value pairs.
50  // If |surface| is not NULL, then it must match |is_offscreen| and |size|,
51  // |window| must be gfx::kNullAcceleratedWidget, and the command buffer
52  // service must run on the same thread as this client because GLSurface is
53  // not thread safe. If |surface| is NULL, then the other parameters are used
54  // to correctly create a surface.
55  // Only one of |share_context| and |use_global_share_group| can be used at
56  // the same time.
57  static GLInProcessContext* Create(
58      scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
59      scoped_refptr<gfx::GLSurface> surface,
60      bool is_offscreen,
61      gfx::AcceleratedWidget window,
62      const gfx::Size& size,
63      GLInProcessContext* share_context,
64      bool use_global_share_group,
65      const gpu::gles2::ContextCreationAttribHelper& attribs,
66      gfx::GpuPreference gpu_preference,
67      const GLInProcessContextSharedMemoryLimits& memory_limits);
68
69  virtual void SetContextLostCallback(const base::Closure& callback) = 0;
70
71  // Allows direct access to the GLES2 implementation so a GLInProcessContext
72  // can be used without making it current.
73  virtual gles2::GLES2Implementation* GetImplementation() = 0;
74
75  virtual size_t GetMappedMemoryLimit() = 0;
76
77#if defined(OS_ANDROID)
78  virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
79      uint32 stream_id) = 0;
80#endif
81};
82
83}  // namespace gpu
84
85#endif  // GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_
86