1 // Copyright 2014 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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_COMPOSITOR_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_COMPOSITOR_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ppapi/host/host_message_context.h"
12 #include "ppapi/host/resource_host.h"
13 #include "ppapi/shared_impl/compositor_layer_data.h"
25 class PepperPluginInstanceImpl
;
26 class RendererPpapiHost
;
28 class PepperCompositorHost
: public ppapi::host::ResourceHost
{
30 PepperCompositorHost(RendererPpapiHost
* host
,
32 PP_Resource resource
);
33 // Associates this device with the given plugin instance. You can pass NULL
34 // to clear the existing device. Returns true on success. In this case, a
35 // repaint of the page will also be scheduled. Failure means that the device
36 // is already bound to a different instance, and nothing will happen.
37 bool BindToInstance(PepperPluginInstanceImpl
* new_instance
);
39 const scoped_refptr
<cc::Layer
> layer() { return layer_
; };
41 void ViewInitiatedPaint();
42 void ViewFlushedPaint();
45 ~PepperCompositorHost() override
;
47 void ImageReleased(int32_t id
,
48 const scoped_ptr
<base::SharedMemory
>& shared_memory
,
51 void ResourceReleased(int32_t id
,
54 void SendCommitLayersReplyIfNecessary();
55 void UpdateLayer(const scoped_refptr
<cc::Layer
>& layer
,
56 const ppapi::CompositorLayerData
* old_layer
,
57 const ppapi::CompositorLayerData
* new_layer
,
58 scoped_ptr
<base::SharedMemory
> image_shm
);
60 // ResourceMessageHandler overrides:
61 int32_t OnResourceMessageReceived(
62 const IPC::Message
& msg
,
63 ppapi::host::HostMessageContext
* context
) override
;
65 // ppapi::host::ResourceHost overrides:
66 bool IsCompositorHost() override
;
69 int32_t OnHostMsgCommitLayers(
70 ppapi::host::HostMessageContext
* context
,
71 const std::vector
<ppapi::CompositorLayerData
>& layers
,
74 // Non-owning pointer to the plugin instance this context is currently bound
75 // to, if any. If the context is currently unbound, this will be NULL.
76 PepperPluginInstanceImpl
* bound_instance_
;
78 // The toplevel cc::Layer. It is the parent of other cc::Layers.
79 scoped_refptr
<cc::Layer
> layer_
;
81 // A list of layers. It is used for updating layers' properties in
82 // subsequent CommitLayers() calls.
84 LayerData(const scoped_refptr
<cc::Layer
>& cc
,
85 const ppapi::CompositorLayerData
& pp
);
88 scoped_refptr
<cc::Layer
> cc_layer
;
89 ppapi::CompositorLayerData pp_layer
;
91 std::vector
<LayerData
> layers_
;
93 ppapi::host::ReplyMessageContext commit_layers_reply_context_
;
95 base::WeakPtrFactory
<PepperCompositorHost
> weak_factory_
;
97 DISALLOW_COPY_AND_ASSIGN(PepperCompositorHost
);
100 } // namespace content
102 #endif // CONTENT_RENDERER_PEPPER_PEPPER_COMPOSITOR_H_