Home | History | Annotate | Download | only in cpp
      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.
      4 
      5 #include "ppapi/cpp/compositor_layer.h"
      6 
      7 #include "ppapi/c/pp_errors.h"
      8 #include "ppapi/cpp/completion_callback.h"
      9 #include "ppapi/cpp/module_impl.h"
     10 #include "ppapi/cpp/var.h"
     11 
     12 namespace pp {
     13 
     14 namespace {
     15 
     16 template <> const char* interface_name<PPB_CompositorLayer_0_1>() {
     17   return PPB_COMPOSITORLAYER_INTERFACE_0_1;
     18 }
     19 
     20 }  // namespace
     21 
     22 CompositorLayer::CompositorLayer() {
     23 }
     24 
     25 CompositorLayer::CompositorLayer(
     26     const CompositorLayer& other) : Resource(other) {
     27 }
     28 
     29 CompositorLayer::CompositorLayer(const Resource& resource)
     30     : Resource(resource) {
     31   PP_DCHECK(IsCompositorLayer(resource));
     32 }
     33 
     34 CompositorLayer::CompositorLayer(PassRef, PP_Resource resource)
     35     : Resource(PASS_REF, resource) {
     36 }
     37 
     38 CompositorLayer::~CompositorLayer() {
     39 }
     40 
     41 int32_t CompositorLayer::SetColor(float red,
     42                                   float green,
     43                                   float blue,
     44                                   float alpha,
     45                                   const Size& size) {
     46   if (has_interface<PPB_CompositorLayer_0_1>()) {
     47     return get_interface<PPB_CompositorLayer_0_1>()->SetColor(
     48         pp_resource(), red, green, blue, alpha, &size.pp_size());
     49   }
     50   return PP_ERROR_NOINTERFACE;
     51 }
     52 
     53 int32_t CompositorLayer::SetTexture(const Graphics3D& context,
     54                                     uint32_t texture,
     55                                     const Size& size,
     56                                     const CompletionCallback& cc) {
     57   if (has_interface<PPB_CompositorLayer_0_1>()) {
     58     return get_interface<PPB_CompositorLayer_0_1>()->SetTexture(
     59         pp_resource(), context.pp_resource(), texture, &size.pp_size(),
     60         cc.pp_completion_callback());
     61   }
     62   return cc.MayForce(PP_ERROR_NOINTERFACE);
     63 }
     64 
     65 int32_t CompositorLayer::SetImage(const ImageData& image,
     66                                   const CompletionCallback& cc) {
     67   if (has_interface<PPB_CompositorLayer_0_1>()) {
     68     return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
     69         pp_resource(), image.pp_resource(), NULL,
     70         cc.pp_completion_callback());
     71   }
     72   return cc.MayForce(PP_ERROR_NOINTERFACE);
     73 }
     74 
     75 int32_t CompositorLayer::SetImage(const ImageData& image,
     76                                   const Size& size,
     77                                   const CompletionCallback& cc) {
     78   if (has_interface<PPB_CompositorLayer_0_1>()) {
     79     return get_interface<PPB_CompositorLayer_0_1>()->SetImage(
     80         pp_resource(), image.pp_resource(), &size.pp_size(),
     81         cc.pp_completion_callback());
     82   }
     83   return cc.MayForce(PP_ERROR_NOINTERFACE);
     84 }
     85 
     86 int32_t CompositorLayer::SetClipRect(const Rect& rect) {
     87   if (has_interface<PPB_CompositorLayer_0_1>()) {
     88     return get_interface<PPB_CompositorLayer_0_1>()->SetClipRect(
     89         pp_resource(), &rect.pp_rect());
     90   }
     91   return PP_ERROR_NOINTERFACE;
     92 }
     93 
     94 int32_t CompositorLayer::SetTransform(const float matrix[16]) {
     95   if (has_interface<PPB_CompositorLayer_0_1>()) {
     96     return get_interface<PPB_CompositorLayer_0_1>()->SetTransform(
     97         pp_resource(), matrix);
     98   }
     99   return PP_ERROR_NOINTERFACE;
    100 }
    101 
    102 int32_t CompositorLayer::SetOpacity(float opacity) {
    103   if (has_interface<PPB_CompositorLayer_0_1>()) {
    104     return get_interface<PPB_CompositorLayer_0_1>()->SetOpacity(
    105         pp_resource(), opacity);
    106   }
    107   return PP_ERROR_NOINTERFACE;
    108 }
    109 
    110 int32_t CompositorLayer::SetBlendMode(PP_BlendMode mode) {
    111   if (has_interface<PPB_CompositorLayer_0_1>()) {
    112     return get_interface<PPB_CompositorLayer_0_1>()->SetBlendMode(
    113         pp_resource(), mode);
    114   }
    115   return PP_ERROR_NOINTERFACE;
    116 }
    117 
    118 int32_t CompositorLayer::SetSourceRect(const FloatRect& rect) {
    119   if (has_interface<PPB_CompositorLayer_0_1>()) {
    120     return get_interface<PPB_CompositorLayer_0_1>()->SetSourceRect(
    121         pp_resource(), &rect.pp_float_rect());
    122   }
    123   return PP_ERROR_NOINTERFACE;
    124 }
    125 
    126 int32_t CompositorLayer::SetPremultipliedAlpha(bool premult) {
    127   if (has_interface<PPB_CompositorLayer_0_1>()) {
    128     return get_interface<PPB_CompositorLayer_0_1>()->SetPremultipliedAlpha(
    129         pp_resource(), PP_FromBool(premult));
    130   }
    131   return PP_ERROR_NOINTERFACE;
    132 }
    133 
    134 bool CompositorLayer::IsCompositorLayer(const Resource& resource) {
    135   if (has_interface<PPB_CompositorLayer_0_1>()) {
    136     return PP_ToBool(get_interface<PPB_CompositorLayer_0_1>()->
    137         IsCompositorLayer(resource.pp_resource()));
    138   }
    139   return false;
    140 }
    141 
    142 }  // namespace pp
    143