Skip to content

Commit

Permalink
[PPAPI] Add target param for CompositorLayer::SetTexture().
Browse files Browse the repository at this point in the history
BUG=403504

Review URL: https://codereview.chromium.org/475123003

Cr-Commit-Position: refs/heads/master@{#290016}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290016 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
penghuang@chromium.org committed Aug 15, 2014
1 parent d904aee commit 1c28b79
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 15 deletions.
2 changes: 1 addition & 1 deletion content/renderer/pepper/pepper_compositor_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void PepperCompositorHost::UpdateLayer(
if (!old_layer ||
new_layer->common.resource_id != old_layer->common.resource_id) {
cc::TextureMailbox mailbox(new_layer->texture->mailbox,
GL_TEXTURE_2D,
new_layer->texture->target,
new_layer->texture->sync_point);
texture_layer->SetTextureMailbox(mailbox,
cc::SingleReleaseCallback::Create(
Expand Down
31 changes: 30 additions & 1 deletion ppapi/api/ppb_compositor_layer.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[generate_thunk]

label Chrome {
[channel=dev] M37 = 0.1
[channel=dev] M37 = 0.1,
[channel=dev] M38 = 0.2
};

/**
Expand Down Expand Up @@ -107,6 +108,34 @@ interface PPB_CompositorLayer {
[in] PP_Size size,
[in] PP_CompletionCallback cc);

/**
* Sets the texture of a texture layer. If the layer is uninitialized,
* it will initialize the layer first, and then set its texture.
* The source rect will be set to ((0, 0), (1, 1)). If the layer has been
* initialized to another kind of layer, the layer will not be changed,
* and <code>PP_ERROR_BADARGUMENT</code> will be returned.
*
* param[in] layer A <code>PP_Resource</code> corresponding to a compositor
* layer resource.
* param[in] context A <code>PP_Resource</code> corresponding to a graphics
* 3d resource which owns the GL texture.
* param[in] target GL texture target (GL_TEXTURE_2D, etc).
* param[in] texture A GL texture object id.
* param[in] size A <code>PP_Size</code> for the size of the layer before
* transform.
* param[in] cc A <code>PP_CompletionCallback</code> to be called when
* the texture is released by Chromium compositor.
*
* @return An int32_t containing a result code from <code>pp_errors.h</code>.
*/
[version = 0.2]
int32_t SetTexture([in] PP_Resource layer,
[in] PP_Resource context,
[in] uint32_t target,
[in] uint32_t texture,
[in] PP_Size size,
[in] PP_CompletionCallback cc);

/**
* Sets the image of an image layer. If the layer is uninitialized,
* it will initialize the layer first, and then set its image.
Expand Down
4 changes: 2 additions & 2 deletions ppapi/c/pp_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* found in the LICENSE file.
*/

/* From pp_macros.idl modified Tue May 20 17:13:23 2014. */
/* From pp_macros.idl modified Wed Jun 11 11:38:24 2014. */

#ifndef PPAPI_C_PP_MACROS_H_
#define PPAPI_C_PP_MACROS_H_


#define PPAPI_RELEASE 37
#define PPAPI_RELEASE 38

/**
* @file
Expand Down
32 changes: 30 additions & 2 deletions ppapi/c/ppb_compositor_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* found in the LICENSE file.
*/

/* From ppb_compositor_layer.idl modified Wed Jun 4 11:17:54 2014. */
/* From ppb_compositor_layer.idl modified Thu Aug 14 18:06:33 2014. */

#ifndef PPAPI_C_PPB_COMPOSITOR_LAYER_H_
#define PPAPI_C_PPB_COMPOSITOR_LAYER_H_
Expand All @@ -18,6 +18,7 @@
#include "ppapi/c/pp_stdint.h"

#define PPB_COMPOSITORLAYER_INTERFACE_0_1 "PPB_CompositorLayer;0.1" /* dev */
#define PPB_COMPOSITORLAYER_INTERFACE_0_2 "PPB_CompositorLayer;0.2" /* dev */
/**
* @file
*/
Expand Down Expand Up @@ -65,7 +66,7 @@ typedef enum {
* Defines the <code>PPB_CompositorLayer</code> interface. It is used by
* <code>PPB_Compositor</code>.
*/
struct PPB_CompositorLayer_0_1 { /* dev */
struct PPB_CompositorLayer_0_2 { /* dev */
/**
* Determines if a resource is a compositor layer resource.
*
Expand Down Expand Up @@ -114,6 +115,7 @@ struct PPB_CompositorLayer_0_1 { /* dev */
* layer resource.
* param[in] context A <code>PP_Resource</code> corresponding to a graphics
* 3d resource which owns the GL texture.
* param[in] target GL texture target (GL_TEXTURE_2D, etc).
* param[in] texture A GL texture object id.
* param[in] size A <code>PP_Size</code> for the size of the layer before
* transform.
Expand All @@ -124,6 +126,7 @@ struct PPB_CompositorLayer_0_1 { /* dev */
*/
int32_t (*SetTexture)(PP_Resource layer,
PP_Resource context,
uint32_t target,
uint32_t texture,
const struct PP_Size* size,
struct PP_CompletionCallback cc);
Expand Down Expand Up @@ -228,6 +231,31 @@ struct PPB_CompositorLayer_0_1 { /* dev */
*/
int32_t (*SetPremultipliedAlpha)(PP_Resource layer, PP_Bool premult);
};

struct PPB_CompositorLayer_0_1 { /* dev */
PP_Bool (*IsCompositorLayer)(PP_Resource resource);
int32_t (*SetColor)(PP_Resource layer,
float red,
float green,
float blue,
float alpha,
const struct PP_Size* size);
int32_t (*SetTexture)(PP_Resource layer,
PP_Resource context,
uint32_t texture,
const struct PP_Size* size,
struct PP_CompletionCallback cc);
int32_t (*SetImage)(PP_Resource layer,
PP_Resource image_data,
const struct PP_Size* size,
struct PP_CompletionCallback cc);
int32_t (*SetClipRect)(PP_Resource layer, const struct PP_Rect* rect);
int32_t (*SetTransform)(PP_Resource layer, const float matrix[16]);
int32_t (*SetOpacity)(PP_Resource layer, float opacity);
int32_t (*SetBlendMode)(PP_Resource layer, PP_BlendMode mode);
int32_t (*SetSourceRect)(PP_Resource layer, const struct PP_FloatRect* rect);
int32_t (*SetPremultipliedAlpha)(PP_Resource layer, PP_Bool premult);
};
/**
* @}
*/
Expand Down
54 changes: 54 additions & 0 deletions ppapi/cpp/compositor_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ template <> const char* interface_name<PPB_CompositorLayer_0_1>() {
return PPB_COMPOSITORLAYER_INTERFACE_0_1;
}

template <> const char* interface_name<PPB_CompositorLayer_0_2>() {
return PPB_COMPOSITORLAYER_INTERFACE_0_2;
}

} // namespace

CompositorLayer::CompositorLayer() {
Expand All @@ -43,6 +47,10 @@ int32_t CompositorLayer::SetColor(float red,
float blue,
float alpha,
const Size& size) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetColor(
pp_resource(), red, green, blue, alpha, &size.pp_size());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetColor(
pp_resource(), red, green, blue, alpha, &size.pp_size());
Expand All @@ -51,10 +59,18 @@ int32_t CompositorLayer::SetColor(float red,
}

int32_t CompositorLayer::SetTexture(const Graphics3D& context,
uint32_t target,
uint32_t texture,
const Size& size,
const CompletionCallback& cc) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetTexture(
pp_resource(), context.pp_resource(), target, texture, &size.pp_size(),
cc.pp_completion_callback());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
if (target != 0x0DE1) // 0x0DE1 GL_TEXTURE_2D
return cc.MayForce(PP_ERROR_NOTSUPPORTED);
return get_interface<PPB_CompositorLayer_0_1>()->SetTexture(
pp_resource(), context.pp_resource(), texture, &size.pp_size(),
cc.pp_completion_callback());
Expand All @@ -64,6 +80,11 @@ int32_t CompositorLayer::SetTexture(const Graphics3D& context,

int32_t CompositorLayer::SetImage(const ImageData& image,
const CompletionCallback& cc) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetImage(
pp_resource(), image.pp_resource(), NULL,
cc.pp_completion_callback());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
pp_resource(), image.pp_resource(), NULL,
Expand All @@ -75,6 +96,11 @@ int32_t CompositorLayer::SetImage(const ImageData& image,
int32_t CompositorLayer::SetImage(const ImageData& image,
const Size& size,
const CompletionCallback& cc) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetImage(
pp_resource(), image.pp_resource(), &size.pp_size(),
cc.pp_completion_callback());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
pp_resource(), image.pp_resource(), &size.pp_size(),
Expand All @@ -84,6 +110,10 @@ int32_t CompositorLayer::SetImage(const ImageData& image,
}

int32_t CompositorLayer::SetClipRect(const Rect& rect) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetClipRect(
pp_resource(), &rect.pp_rect());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetClipRect(
pp_resource(), &rect.pp_rect());
Expand All @@ -92,6 +122,10 @@ int32_t CompositorLayer::SetClipRect(const Rect& rect) {
}

int32_t CompositorLayer::SetTransform(const float matrix[16]) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetTransform(
pp_resource(), matrix);
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetTransform(
pp_resource(), matrix);
Expand All @@ -100,6 +134,10 @@ int32_t CompositorLayer::SetTransform(const float matrix[16]) {
}

int32_t CompositorLayer::SetOpacity(float opacity) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetOpacity(
pp_resource(), opacity);
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetOpacity(
pp_resource(), opacity);
Expand All @@ -108,6 +146,10 @@ int32_t CompositorLayer::SetOpacity(float opacity) {
}

int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetBlendMode(
pp_resource(), mode);
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetBlendMode(
pp_resource(), mode);
Expand All @@ -116,6 +158,10 @@ int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) {
}

int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetSourceRect(
pp_resource(), &rect.pp_float_rect());
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetSourceRect(
pp_resource(), &rect.pp_float_rect());
Expand All @@ -124,6 +170,10 @@ int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) {
}

int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return get_interface<PPB_CompositorLayer_0_2>()->SetPremultipliedAlpha(
pp_resource(), PP_FromBool(premult));
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return get_interface<PPB_CompositorLayer_0_1>()->SetPremultipliedAlpha(
pp_resource(), PP_FromBool(premult));
Expand All @@ -132,6 +182,10 @@ int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) {
}

bool CompositorLayer::IsCompositorLayer(const Resource& resource) {
if (has_interface<PPB_CompositorLayer_0_2>()) {
return PP_ToBool(get_interface<PPB_CompositorLayer_0_2>()->
IsCompositorLayer(resource.pp_resource()));
}
if (has_interface<PPB_CompositorLayer_0_1>()) {
return PP_ToBool(get_interface<PPB_CompositorLayer_0_1>()->
IsCompositorLayer(resource.pp_resource()));
Expand Down
2 changes: 2 additions & 0 deletions ppapi/cpp/compositor_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CompositorLayer : public Resource {
///
/// param[in] context A <code>Graphics3D</code> corresponding to a graphics 3d
/// resource which owns the GL texture.
/// param[in] target GL texture target (GL_TEXTURE_2D, etc).
/// param[in] texture A GL texture object id.
/// param[in] size A <code>Size</code> for the size of the layer before
/// transform.
Expand All @@ -78,6 +79,7 @@ class CompositorLayer : public Resource {
///
/// @return An int32_t containing a result code from <code>pp_errors.h</code>.
int32_t SetTexture(const Graphics3D& context,
uint32_t target,
uint32_t texture,
const Size& size,
const CompletionCallback& cc);
Expand Down
10 changes: 8 additions & 2 deletions ppapi/examples/compositor/compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ void DemoInstance::PrepareLayers(int32_t frame) {
cube_->Draw();
rv = stable_texture_layer_.SetTexture(
*context_,
texture, pp::Size(600, 600),
GL_TEXTURE_2D,
texture,
pp::Size(600, 600),
callback_factory_.NewCallback(&DemoInstance::OnTextureReleased,
texture));
assert(rv == PP_OK_COMPLETIONPENDING);
Expand Down Expand Up @@ -397,7 +399,11 @@ void DemoInstance::PrepareLayers(int32_t frame) {
GLuint texture = PrepareFramebuffer();
cube_->UpdateForTimeDelta(0.02f);
cube_->Draw();
rv = texture_layer_.SetTexture(*context_, texture, pp::Size(400, 400),
rv = texture_layer_.SetTexture(
*context_,
GL_TEXTURE_2D,
texture,
pp::Size(400, 400),
callback_factory_.NewCallback(&DemoInstance::OnTextureReleased,
texture));
assert(rv == PP_OK_COMPLETIONPENDING);
Expand Down
Loading

0 comments on commit 1c28b79

Please sign in to comment.