| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/cpp/compositor_layer.h" | 5 #include "ppapi/cpp/compositor_layer.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/cpp/completion_callback.h" | 8 #include "ppapi/cpp/completion_callback.h" |
| 9 #include "ppapi/cpp/module_impl.h" | 9 #include "ppapi/cpp/module_impl.h" |
| 10 #include "ppapi/cpp/var.h" | 10 #include "ppapi/cpp/var.h" |
| 11 | 11 |
| 12 namespace pp { | 12 namespace pp { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 template <> const char* interface_name<PPB_CompositorLayer_0_1>() { | 16 template <> const char* interface_name<PPB_CompositorLayer_0_1>() { |
| 17 return PPB_COMPOSITORLAYER_INTERFACE_0_1; | 17 return PPB_COMPOSITORLAYER_INTERFACE_0_1; |
| 18 } | 18 } |
| 19 | 19 |
| 20 template <> const char* interface_name<PPB_CompositorLayer_0_2>() { |
| 21 return PPB_COMPOSITORLAYER_INTERFACE_0_2; |
| 22 } |
| 23 |
| 20 } // namespace | 24 } // namespace |
| 21 | 25 |
| 22 CompositorLayer::CompositorLayer() { | 26 CompositorLayer::CompositorLayer() { |
| 23 } | 27 } |
| 24 | 28 |
| 25 CompositorLayer::CompositorLayer( | 29 CompositorLayer::CompositorLayer( |
| 26 const CompositorLayer& other) : Resource(other) { | 30 const CompositorLayer& other) : Resource(other) { |
| 27 } | 31 } |
| 28 | 32 |
| 29 CompositorLayer::CompositorLayer(const Resource& resource) | 33 CompositorLayer::CompositorLayer(const Resource& resource) |
| 30 : Resource(resource) { | 34 : Resource(resource) { |
| 31 PP_DCHECK(IsCompositorLayer(resource)); | 35 PP_DCHECK(IsCompositorLayer(resource)); |
| 32 } | 36 } |
| 33 | 37 |
| 34 CompositorLayer::CompositorLayer(PassRef, PP_Resource resource) | 38 CompositorLayer::CompositorLayer(PassRef, PP_Resource resource) |
| 35 : Resource(PASS_REF, resource) { | 39 : Resource(PASS_REF, resource) { |
| 36 } | 40 } |
| 37 | 41 |
| 38 CompositorLayer::~CompositorLayer() { | 42 CompositorLayer::~CompositorLayer() { |
| 39 } | 43 } |
| 40 | 44 |
| 41 int32_t CompositorLayer::SetColor(float red, | 45 int32_t CompositorLayer::SetColor(float red, |
| 42 float green, | 46 float green, |
| 43 float blue, | 47 float blue, |
| 44 float alpha, | 48 float alpha, |
| 45 const Size& size) { | 49 const Size& size) { |
| 50 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 51 return get_interface<PPB_CompositorLayer_0_2>()->SetColor( |
| 52 pp_resource(), red, green, blue, alpha, &size.pp_size()); |
| 53 } |
| 46 if (has_interface<PPB_CompositorLayer_0_1>()) { | 54 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 47 return get_interface<PPB_CompositorLayer_0_1>()->SetColor( | 55 return get_interface<PPB_CompositorLayer_0_1>()->SetColor( |
| 48 pp_resource(), red, green, blue, alpha, &size.pp_size()); | 56 pp_resource(), red, green, blue, alpha, &size.pp_size()); |
| 49 } | 57 } |
| 50 return PP_ERROR_NOINTERFACE; | 58 return PP_ERROR_NOINTERFACE; |
| 51 } | 59 } |
| 52 | 60 |
| 53 int32_t CompositorLayer::SetTexture(const Graphics3D& context, | 61 int32_t CompositorLayer::SetTexture(const Graphics3D& context, |
| 62 uint32_t target, |
| 54 uint32_t texture, | 63 uint32_t texture, |
| 55 const Size& size, | 64 const Size& size, |
| 56 const CompletionCallback& cc) { | 65 const CompletionCallback& cc) { |
| 66 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 67 return get_interface<PPB_CompositorLayer_0_2>()->SetTexture( |
| 68 pp_resource(), context.pp_resource(), target, texture, &size.pp_size(), |
| 69 cc.pp_completion_callback()); |
| 70 } |
| 57 if (has_interface<PPB_CompositorLayer_0_1>()) { | 71 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 72 if (target != 0x0DE1) // 0x0DE1 GL_TEXTURE_2D |
| 73 return cc.MayForce(PP_ERROR_NOTSUPPORTED); |
| 58 return get_interface<PPB_CompositorLayer_0_1>()->SetTexture( | 74 return get_interface<PPB_CompositorLayer_0_1>()->SetTexture( |
| 59 pp_resource(), context.pp_resource(), texture, &size.pp_size(), | 75 pp_resource(), context.pp_resource(), texture, &size.pp_size(), |
| 60 cc.pp_completion_callback()); | 76 cc.pp_completion_callback()); |
| 61 } | 77 } |
| 62 return cc.MayForce(PP_ERROR_NOINTERFACE); | 78 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 63 } | 79 } |
| 64 | 80 |
| 65 int32_t CompositorLayer::SetImage(const ImageData& image, | 81 int32_t CompositorLayer::SetImage(const ImageData& image, |
| 66 const CompletionCallback& cc) { | 82 const CompletionCallback& cc) { |
| 83 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 84 return get_interface<PPB_CompositorLayer_0_2>()->SetImage( |
| 85 pp_resource(), image.pp_resource(), NULL, |
| 86 cc.pp_completion_callback()); |
| 87 } |
| 67 if (has_interface<PPB_CompositorLayer_0_1>()) { | 88 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 68 return get_interface<PPB_CompositorLayer_0_1>()->SetImage( | 89 return get_interface<PPB_CompositorLayer_0_1>()->SetImage( |
| 69 pp_resource(), image.pp_resource(), NULL, | 90 pp_resource(), image.pp_resource(), NULL, |
| 70 cc.pp_completion_callback()); | 91 cc.pp_completion_callback()); |
| 71 } | 92 } |
| 72 return cc.MayForce(PP_ERROR_NOINTERFACE); | 93 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 73 } | 94 } |
| 74 | 95 |
| 75 int32_t CompositorLayer::SetImage(const ImageData& image, | 96 int32_t CompositorLayer::SetImage(const ImageData& image, |
| 76 const Size& size, | 97 const Size& size, |
| 77 const CompletionCallback& cc) { | 98 const CompletionCallback& cc) { |
| 99 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 100 return get_interface<PPB_CompositorLayer_0_2>()->SetImage( |
| 101 pp_resource(), image.pp_resource(), &size.pp_size(), |
| 102 cc.pp_completion_callback()); |
| 103 } |
| 78 if (has_interface<PPB_CompositorLayer_0_1>()) { | 104 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 79 return get_interface<PPB_CompositorLayer_0_1>()->SetImage( | 105 return get_interface<PPB_CompositorLayer_0_1>()->SetImage( |
| 80 pp_resource(), image.pp_resource(), &size.pp_size(), | 106 pp_resource(), image.pp_resource(), &size.pp_size(), |
| 81 cc.pp_completion_callback()); | 107 cc.pp_completion_callback()); |
| 82 } | 108 } |
| 83 return cc.MayForce(PP_ERROR_NOINTERFACE); | 109 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 84 } | 110 } |
| 85 | 111 |
| 86 int32_t CompositorLayer::SetClipRect(const Rect& rect) { | 112 int32_t CompositorLayer::SetClipRect(const Rect& rect) { |
| 113 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 114 return get_interface<PPB_CompositorLayer_0_2>()->SetClipRect( |
| 115 pp_resource(), &rect.pp_rect()); |
| 116 } |
| 87 if (has_interface<PPB_CompositorLayer_0_1>()) { | 117 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 88 return get_interface<PPB_CompositorLayer_0_1>()->SetClipRect( | 118 return get_interface<PPB_CompositorLayer_0_1>()->SetClipRect( |
| 89 pp_resource(), &rect.pp_rect()); | 119 pp_resource(), &rect.pp_rect()); |
| 90 } | 120 } |
| 91 return PP_ERROR_NOINTERFACE; | 121 return PP_ERROR_NOINTERFACE; |
| 92 } | 122 } |
| 93 | 123 |
| 94 int32_t CompositorLayer::SetTransform(const float matrix[16]) { | 124 int32_t CompositorLayer::SetTransform(const float matrix[16]) { |
| 125 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 126 return get_interface<PPB_CompositorLayer_0_2>()->SetTransform( |
| 127 pp_resource(), matrix); |
| 128 } |
| 95 if (has_interface<PPB_CompositorLayer_0_1>()) { | 129 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 96 return get_interface<PPB_CompositorLayer_0_1>()->SetTransform( | 130 return get_interface<PPB_CompositorLayer_0_1>()->SetTransform( |
| 97 pp_resource(), matrix); | 131 pp_resource(), matrix); |
| 98 } | 132 } |
| 99 return PP_ERROR_NOINTERFACE; | 133 return PP_ERROR_NOINTERFACE; |
| 100 } | 134 } |
| 101 | 135 |
| 102 int32_t CompositorLayer::SetOpacity(float opacity) { | 136 int32_t CompositorLayer::SetOpacity(float opacity) { |
| 137 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 138 return get_interface<PPB_CompositorLayer_0_2>()->SetOpacity( |
| 139 pp_resource(), opacity); |
| 140 } |
| 103 if (has_interface<PPB_CompositorLayer_0_1>()) { | 141 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 104 return get_interface<PPB_CompositorLayer_0_1>()->SetOpacity( | 142 return get_interface<PPB_CompositorLayer_0_1>()->SetOpacity( |
| 105 pp_resource(), opacity); | 143 pp_resource(), opacity); |
| 106 } | 144 } |
| 107 return PP_ERROR_NOINTERFACE; | 145 return PP_ERROR_NOINTERFACE; |
| 108 } | 146 } |
| 109 | 147 |
| 110 int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) { | 148 int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) { |
| 149 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 150 return get_interface<PPB_CompositorLayer_0_2>()->SetBlendMode( |
| 151 pp_resource(), mode); |
| 152 } |
| 111 if (has_interface<PPB_CompositorLayer_0_1>()) { | 153 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 112 return get_interface<PPB_CompositorLayer_0_1>()->SetBlendMode( | 154 return get_interface<PPB_CompositorLayer_0_1>()->SetBlendMode( |
| 113 pp_resource(), mode); | 155 pp_resource(), mode); |
| 114 } | 156 } |
| 115 return PP_ERROR_NOINTERFACE; | 157 return PP_ERROR_NOINTERFACE; |
| 116 } | 158 } |
| 117 | 159 |
| 118 int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) { | 160 int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) { |
| 161 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 162 return get_interface<PPB_CompositorLayer_0_2>()->SetSourceRect( |
| 163 pp_resource(), &rect.pp_float_rect()); |
| 164 } |
| 119 if (has_interface<PPB_CompositorLayer_0_1>()) { | 165 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 120 return get_interface<PPB_CompositorLayer_0_1>()->SetSourceRect( | 166 return get_interface<PPB_CompositorLayer_0_1>()->SetSourceRect( |
| 121 pp_resource(), &rect.pp_float_rect()); | 167 pp_resource(), &rect.pp_float_rect()); |
| 122 } | 168 } |
| 123 return PP_ERROR_NOINTERFACE; | 169 return PP_ERROR_NOINTERFACE; |
| 124 } | 170 } |
| 125 | 171 |
| 126 int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) { | 172 int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) { |
| 173 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 174 return get_interface<PPB_CompositorLayer_0_2>()->SetPremultipliedAlpha( |
| 175 pp_resource(), PP_FromBool(premult)); |
| 176 } |
| 127 if (has_interface<PPB_CompositorLayer_0_1>()) { | 177 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 128 return get_interface<PPB_CompositorLayer_0_1>()->SetPremultipliedAlpha( | 178 return get_interface<PPB_CompositorLayer_0_1>()->SetPremultipliedAlpha( |
| 129 pp_resource(), PP_FromBool(premult)); | 179 pp_resource(), PP_FromBool(premult)); |
| 130 } | 180 } |
| 131 return PP_ERROR_NOINTERFACE; | 181 return PP_ERROR_NOINTERFACE; |
| 132 } | 182 } |
| 133 | 183 |
| 134 bool CompositorLayer::IsCompositorLayer(const Resource& resource) { | 184 bool CompositorLayer::IsCompositorLayer(const Resource& resource) { |
| 185 if (has_interface<PPB_CompositorLayer_0_2>()) { |
| 186 return PP_ToBool(get_interface<PPB_CompositorLayer_0_2>()-> |
| 187 IsCompositorLayer(resource.pp_resource())); |
| 188 } |
| 135 if (has_interface<PPB_CompositorLayer_0_1>()) { | 189 if (has_interface<PPB_CompositorLayer_0_1>()) { |
| 136 return PP_ToBool(get_interface<PPB_CompositorLayer_0_1>()-> | 190 return PP_ToBool(get_interface<PPB_CompositorLayer_0_1>()-> |
| 137 IsCompositorLayer(resource.pp_resource())); | 191 IsCompositorLayer(resource.pp_resource())); |
| 138 } | 192 } |
| 139 return false; | 193 return false; |
| 140 } | 194 } |
| 141 | 195 |
| 142 } // namespace pp | 196 } // namespace pp |
| OLD | NEW |