summaryrefslogtreecommitdiff
path: root/chromium/gpu/gles2_conform_support/egl/context.h
blob: 585d26ef9b1804dd036c71c1e6240d73fccb6023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_GLES2_CONFORM_TEST_CONTEXT_H_
#define GPU_GLES2_CONFORM_TEST_CONTEXT_H_

#include <memory>

#include <EGL/egl.h>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
#include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/service/command_buffer_direct.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/mailbox_manager_impl.h"
#include "gpu/command_buffer/service/service_discardable_manager.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"

namespace gpu {
class ServiceDiscardableManager;
class TransferBuffer;

namespace gles2 {
class GLES2CmdHelper;
class GLES2Interface;
}  // namespace gles2
}  // namespace gpu

namespace egl {
class Display;
class Surface;
class Config;

class Context : public base::RefCountedThreadSafe<Context>,
                private gpu::GpuControl {
 public:
  Context(Display* display, const Config* config);
  bool is_current_in_some_thread() const { return is_current_in_some_thread_; }
  void set_is_current_in_some_thread(bool flag) {
    is_current_in_some_thread_ = flag;
  }
  void MarkDestroyed();
  bool SwapBuffers(Surface* current_surface);

  static bool MakeCurrent(Context* current_context,
                          Surface* current_surface,
                          Context* new_context,
                          Surface* new_surface);

  static bool ValidateAttributeList(const EGLint* attrib_list);

  // GpuControl implementation.
  void SetGpuControlClient(gpu::GpuControlClient*) override;
  gpu::Capabilities GetCapabilities() override;
  int32_t CreateImage(ClientBuffer buffer,
                      size_t width,
                      size_t height,
                      unsigned internalformat) override;
  void DestroyImage(int32_t id) override;
  void SignalQuery(uint32_t query, const base::Closure& callback) override;
  void SetLock(base::Lock*) override;
  void EnsureWorkVisible() override;
  gpu::CommandBufferNamespace GetNamespaceID() const override;
  gpu::CommandBufferId GetCommandBufferID() const override;
  void FlushPendingWork() override;
  uint64_t GenerateFenceSyncRelease() override;
  bool IsFenceSyncRelease(uint64_t release) override;
  bool IsFenceSyncFlushed(uint64_t release) override;
  bool IsFenceSyncFlushReceived(uint64_t release) override;
  bool IsFenceSyncReleased(uint64_t release) override;
  void SignalSyncToken(const gpu::SyncToken& sync_token,
                       const base::Closure& callback) override;
  void WaitSyncTokenHint(const gpu::SyncToken& sync_token) override;
  bool CanWaitUnverifiedSyncToken(const gpu::SyncToken& sync_token) override;
  void AddLatencyInfo(
      const std::vector<ui::LatencyInfo>& latency_info) override;

  // Called by ThreadState to set the needed global variables when this context
  // is current.
  void ApplyCurrentContext(gl::GLSurface* current_surface);
  static void ApplyContextReleased();

  static void SetPlatformGpuFeatureInfo(
      const gpu::GpuFeatureInfo& gpu_feature_info);

 private:
  friend class base::RefCountedThreadSafe<Context>;
  ~Context() override;
  bool CreateService(gl::GLSurface* gl_surface);
  void DestroyService();
  // Returns true if the object has GL service, either a working one or one
  // that has lost its GL context.
  bool HasService() const;
  void MarkServiceContextLost();
  bool WasServiceContextLost() const;
  bool IsCompatibleSurface(Surface* surface) const;
  bool Flush(gl::GLSurface* gl_surface);

  static gpu::GpuFeatureInfo platform_gpu_feature_info_;

  Display* display_;
  const Config* config_;
  bool is_current_in_some_thread_;
  bool is_destroyed_;
  const gpu::GpuDriverBugWorkarounds gpu_driver_bug_workarounds_;
  std::unique_ptr<gpu::TransferBufferManager> transfer_buffer_manager_;
  std::unique_ptr<gpu::CommandBufferDirect> command_buffer_;
  std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_;

  gpu::gles2::MailboxManagerImpl mailbox_manager_;
  gpu::gles2::ImageManager image_manager_;
  gpu::ServiceDiscardableManager discardable_manager_;
  gpu::gles2::ShaderTranslatorCache translator_cache_;
  gpu::gles2::FramebufferCompletenessCache completeness_cache_;
  std::unique_ptr<gpu::gles2::GLES2Decoder> decoder_;
  std::unique_ptr<gpu::TransferBuffer> transfer_buffer_;

  scoped_refptr<gl::GLContext> gl_context_;

  std::unique_ptr<gpu::gles2::GLES2Interface> client_gl_context_;

  DISALLOW_COPY_AND_ASSIGN(Context);
};

}  // namespace egl

#endif  // GPU_GLES2_CONFORM_TEST_CONTEXT_H_