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"
26 class PepperPluginInstanceImpl
;
27 class RendererPpapiHost
;
29 class PepperCompositorHost
: public ppapi::host::ResourceHost
{
31 PepperCompositorHost(RendererPpapiHost
* host
,
33 PP_Resource resource
);
34 // Associates this device with the given plugin instance. You can pass NULL
35 // to clear the existing device. Returns true on success. In this case, a
36 // repaint of the page will also be scheduled. Failure means that the device
37 // is already bound to a different instance, and nothing will happen.
38 bool BindToInstance(PepperPluginInstanceImpl
* new_instance
);
40 const scoped_refptr
<cc::Layer
> layer() { return layer_
; };
42 void ViewInitiatedPaint();
45 ~PepperCompositorHost() override
;
47 void ImageReleased(int32_t id
,
48 scoped_ptr
<base::SharedMemory
> shared_memory
,
49 scoped_ptr
<cc::SharedBitmap
> bitmap
,
52 void ResourceReleased(int32_t id
,
55 void SendCommitLayersReplyIfNecessary();
56 void UpdateLayer(const scoped_refptr
<cc::Layer
>& layer
,
57 const ppapi::CompositorLayerData
* old_layer
,
58 const ppapi::CompositorLayerData
* new_layer
,
59 scoped_ptr
<base::SharedMemory
> image_shm
);
61 // ResourceMessageHandler overrides:
62 int32_t OnResourceMessageReceived(
63 const IPC::Message
& msg
,
64 ppapi::host::HostMessageContext
* context
) override
;
66 // ppapi::host::ResourceHost overrides:
67 bool IsCompositorHost() override
;
70 int32_t OnHostMsgCommitLayers(
71 ppapi::host::HostMessageContext
* context
,
72 const std::vector
<ppapi::CompositorLayerData
>& layers
,
75 // Non-owning pointer to the plugin instance this context is currently bound
76 // to, if any. If the context is currently unbound, this will be NULL.
77 PepperPluginInstanceImpl
* bound_instance_
;
79 // The toplevel cc::Layer. It is the parent of other cc::Layers.
80 scoped_refptr
<cc::Layer
> layer_
;
82 // A list of layers. It is used for updating layers' properties in
83 // subsequent CommitLayers() calls.
85 LayerData(const scoped_refptr
<cc::Layer
>& cc
,
86 const ppapi::CompositorLayerData
& pp
);
89 scoped_refptr
<cc::Layer
> cc_layer
;
90 ppapi::CompositorLayerData pp_layer
;
92 std::vector
<LayerData
> layers_
;
94 ppapi::host::ReplyMessageContext commit_layers_reply_context_
;
96 base::WeakPtrFactory
<PepperCompositorHost
> weak_factory_
;
98 DISALLOW_COPY_AND_ASSIGN(PepperCompositorHost
);
101 } // namespace content
103 #endif // CONTENT_RENDERER_PEPPER_PEPPER_COMPOSITOR_H_