other-licenses/skia-npapi/SkANP.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/skia-npapi/SkANP.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +/*
     1.5 + * Copyright 2008, The Android Open Source Project
     1.6 + *
     1.7 + * Redistribution and use in source and binary forms, with or without
     1.8 + * modification, are permitted provided that the following conditions
     1.9 + * are met:
    1.10 + *  * Redistributions of source code must retain the above copyright
    1.11 + *    notice, this list of conditions and the following disclaimer.
    1.12 + *  * Redistributions in binary form must reproduce the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer in the
    1.14 + *    documentation and/or other materials provided with the distribution.
    1.15 + *
    1.16 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    1.17 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.18 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.19 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.20 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.21 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.22 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.23 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    1.24 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.27 + */
    1.28 +
    1.29 +// must include config.h first for webkit to fiddle with new/delete
    1.30 +#include "SkANP.h"
    1.31 +
    1.32 +SkRect* SkANP::SetRect(SkRect* dst, const ANPRectF& src) {
    1.33 +    dst->set(SkFloatToScalar(src.left),
    1.34 +             SkFloatToScalar(src.top),
    1.35 +             SkFloatToScalar(src.right),
    1.36 +             SkFloatToScalar(src.bottom));
    1.37 +    return dst;
    1.38 +}
    1.39 +
    1.40 +SkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) {
    1.41 +    dst->set(src.left, src.top, src.right, src.bottom);
    1.42 +    return dst;
    1.43 +}
    1.44 +
    1.45 +ANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) {
    1.46 +    dst->left = src.fLeft;
    1.47 +    dst->top = src.fTop;
    1.48 +    dst->right = src.fRight;
    1.49 +    dst->bottom = src.fBottom;
    1.50 +    return dst;
    1.51 +}
    1.52 +
    1.53 +ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) {
    1.54 +    dst->left = SkScalarToFloat(src.fLeft);
    1.55 +    dst->top = SkScalarToFloat(src.fTop);
    1.56 +    dst->right = SkScalarToFloat(src.fRight);
    1.57 +    dst->bottom = SkScalarToFloat(src.fBottom);
    1.58 +    return dst;
    1.59 +}
    1.60 +
    1.61 +SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
    1.62 +    SkBitmap::Config config = SkBitmap::kNo_Config;
    1.63 +    
    1.64 +    switch (src.format) {
    1.65 +        case kRGBA_8888_ANPBitmapFormat:
    1.66 +            config = SkBitmap::kARGB_8888_Config;
    1.67 +            break;
    1.68 +        case kRGB_565_ANPBitmapFormat:
    1.69 +            config = SkBitmap::kRGB_565_Config;
    1.70 +            break;
    1.71 +        default:
    1.72 +            break;
    1.73 +    }
    1.74 +    
    1.75 +    dst->setConfig(config, src.width, src.height, src.rowBytes);
    1.76 +    dst->setPixels(src.baseAddr);
    1.77 +    return dst;
    1.78 +}
    1.79 +
    1.80 +bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) {
    1.81 +    if (!(dst->baseAddr = src.getPixels())) {
    1.82 +        SkDebugf("SkANP::SetBitmap - getPixels() returned null\n");
    1.83 +        return false;
    1.84 +    }
    1.85 +
    1.86 +    switch (src.config()) {
    1.87 +        case SkBitmap::kARGB_8888_Config:
    1.88 +            dst->format = kRGBA_8888_ANPBitmapFormat;
    1.89 +            break;
    1.90 +        case SkBitmap::kRGB_565_Config:
    1.91 +            dst->format = kRGB_565_ANPBitmapFormat;
    1.92 +            break;
    1.93 +        default:
    1.94 +            SkDebugf("SkANP::SetBitmap - unsupported src.config %d\n", src.config());
    1.95 +            return false;
    1.96 +    }
    1.97 +    
    1.98 +    dst->width    = src.width();
    1.99 +    dst->height   = src.height();
   1.100 +    dst->rowBytes = src.rowBytes();
   1.101 +    return true;
   1.102 +}
   1.103 +
   1.104 +void SkANP::InitEvent(ANPEvent* event, ANPEventType et) {
   1.105 +    event->inSize = sizeof(ANPEvent);
   1.106 +    event->eventType = et;
   1.107 +}

mercurial