summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/transport_texture.h
blob: c3291d240a936f5d290f0e800cf0fc1c17e8b1b9 (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
// 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.

// This clasis used together with TansportTextureHost in the renderer process
// to provide a mechanism for an object in the GPU process to create textures
// and be used in the renderer process.
//
// See content/gpu/transport_texture_host.h for usage and details.

#ifndef CONTENT_COMMON_GPU_TRANSPORT_TEXTURE_H_
#define CONTENT_COMMON_GPU_TRANSPORT_TEXTURE_H_

#include <vector>
#include <map>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "ipc/ipc_channel.h"

class GpuChannel;

namespace gpu {
namespace gles2 {
class GLES2Decoder;
}  // namespace gles2
}  // namespace gpu

class TransportTexture : public IPC::Channel::Listener {
 public:
  enum Format {
    RGBA,  // GL_RGBA
  };

  // |channel| is the owner of this object.
  // |sender| is used to send send IPC messages.
  // |decoder| is the decoder for GLES2 command buffer, used to convert texture
  // IDs.
  // |host_id| is ID of TransportTextureHost in Renderer process.
  // |id| is ID of this object in GpuChannel.
  TransportTexture(GpuChannel* channel,
                   IPC::Message::Sender* sender,
                   gpu::gles2::GLES2Decoder* decoder,
                   int32 host_id,
                   int32 route_id);
  virtual ~TransportTexture();

  // Create a set of textures of specified size and format. They will be
  // stored in |textures| and |done_task| will be called.
  // Textures IDs stored in |textures| are in the system GL context.
  void CreateTextures(int n, int width, int height, Format format,
                      std::vector<int>* textures, Task* done_task);

  // Release all textures that have previously been allocated.
  void ReleaseTextures();

  // Notify that the texture has been updated. Notification will be sent to the
  // renderer process.
  void TextureUpdated(int texture_id);

  // IPC::Channel::Listener implementation.
  virtual void OnChannelConnected(int32 peer_pid);
  virtual void OnChannelError();
  virtual bool OnMessageReceived(const IPC::Message& msg);

 private:
  // Mapping from service (GPU) IDs to client (Renderer) IDs.
  typedef std::map<int, int> TextureMap;

  ///////////////////////////////////////////////////////////////////////////
  // IPC Message Handlers
  void OnDestroy();
  void OnTexturesCreated(std::vector<int> textures);

  GpuChannel* channel_;
  IPC::Message::Sender* sender_;
  gpu::gles2::GLES2Decoder* decoder_;

  // ID of TransportTextureHost in the Renderer process.
  int32 host_id_;

  // ID of this object in GpuChannel.
  int32 route_id_;

  // Output pointer to write generated textures.
  std::vector<int>* output_textures_;

  // Task that gets called when textures are generated.
  scoped_ptr<Task> create_task_;

  // Mapping between service (GPU) IDs to client (Renderer) IDs.
  TextureMap texture_map_;

  DISALLOW_COPY_AND_ASSIGN(TransportTexture);
};

#endif  // CONTENT_COMMON_GPU_TRANSPORT_TEXTURE_H_