summaryrefslogtreecommitdiff
path: root/chromium/content/renderer/pepper/pepper_platform_context_3d.h
blob: 2520bbd65da868a70dd9edf8b228a6c244e63f1d (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
// Copyright (c) 2012 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 CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_CONTEXT_3D_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_CONTEXT_3D_H_

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "gpu/command_buffer/common/mailbox.h"

class CommandBufferProxy;
namespace gpu {
class CommandBuffer;
struct Mailbox;
}  // namespace gpu

namespace content {
class ContextProviderCommandBuffer;
class GpuChannelHost;

class PlatformContext3D {
 public:
  explicit PlatformContext3D();
  ~PlatformContext3D();

  // Initialize the context.
  bool Init(const int32* attrib_list, PlatformContext3D* share_context);

  // Retrieves the mailbox name for the front buffer backing the context.
  void GetBackingMailbox(gpu::Mailbox* mailbox);

  // Returns true if the backing texture is always opaque.
  bool IsOpaque();

  // This call will return the address of the command buffer for this context
  // that is constructed in Initialize() and is valid until this context is
  // destroyed.
  gpu::CommandBuffer* GetCommandBuffer();

  // Returns the GpuControl class that services out-of-band messages.
  gpu::GpuControl* GetGpuControl();

  // If the command buffer is routed in the GPU channel, return the route id.
  // Otherwise return 0.
  int GetCommandBufferRouteId();

  // Set an optional callback that will be invoked when the context is lost
  // (e.g. gpu process crash). Takes ownership of the callback.
  typedef base::Callback<void(const std::string&, int)>
        ConsoleMessageCallback;
  void SetContextLostCallback(const base::Closure& callback);

  // Set an optional callback that will be invoked when the GPU process
  // sends a console message.
  void SetOnConsoleMessageCallback(const ConsoleMessageCallback& callback);

  // Run the callback once the channel has been flushed.
  void Echo(const base::Closure& task);

 private:
  bool InitRaw();
  void OnContextLost();
  void OnConsoleMessage(const std::string& msg, int id);

  scoped_refptr<GpuChannelHost> channel_;
  gpu::Mailbox mailbox_;
  bool has_alpha_;
  CommandBufferProxyImpl* command_buffer_;
  base::Closure context_lost_callback_;
  ConsoleMessageCallback console_message_callback_;
  base::WeakPtrFactory<PlatformContext3D> weak_ptr_factory_;
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_CONTEXT_3D_H_