other-licenses/skia-npapi/SkANP.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2008, The Android Open Source Project
     3  *
     4  * Redistribution and use in source and binary forms, with or without
     5  * modification, are permitted provided that the following conditions
     6  * are met:
     7  *  * Redistributions of source code must retain the above copyright
     8  *    notice, this list of conditions and the following disclaimer.
     9  *  * Redistributions in binary form must reproduce the above copyright
    10  *    notice, this list of conditions and the following disclaimer in the
    11  *    documentation and/or other materials provided with the distribution.
    12  *
    13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    24  */
    26 // must include config.h first for webkit to fiddle with new/delete
    27 #include "SkANP.h"
    29 SkRect* SkANP::SetRect(SkRect* dst, const ANPRectF& src) {
    30     dst->set(SkFloatToScalar(src.left),
    31              SkFloatToScalar(src.top),
    32              SkFloatToScalar(src.right),
    33              SkFloatToScalar(src.bottom));
    34     return dst;
    35 }
    37 SkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) {
    38     dst->set(src.left, src.top, src.right, src.bottom);
    39     return dst;
    40 }
    42 ANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) {
    43     dst->left = src.fLeft;
    44     dst->top = src.fTop;
    45     dst->right = src.fRight;
    46     dst->bottom = src.fBottom;
    47     return dst;
    48 }
    50 ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) {
    51     dst->left = SkScalarToFloat(src.fLeft);
    52     dst->top = SkScalarToFloat(src.fTop);
    53     dst->right = SkScalarToFloat(src.fRight);
    54     dst->bottom = SkScalarToFloat(src.fBottom);
    55     return dst;
    56 }
    58 SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
    59     SkBitmap::Config config = SkBitmap::kNo_Config;
    61     switch (src.format) {
    62         case kRGBA_8888_ANPBitmapFormat:
    63             config = SkBitmap::kARGB_8888_Config;
    64             break;
    65         case kRGB_565_ANPBitmapFormat:
    66             config = SkBitmap::kRGB_565_Config;
    67             break;
    68         default:
    69             break;
    70     }
    72     dst->setConfig(config, src.width, src.height, src.rowBytes);
    73     dst->setPixels(src.baseAddr);
    74     return dst;
    75 }
    77 bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) {
    78     if (!(dst->baseAddr = src.getPixels())) {
    79         SkDebugf("SkANP::SetBitmap - getPixels() returned null\n");
    80         return false;
    81     }
    83     switch (src.config()) {
    84         case SkBitmap::kARGB_8888_Config:
    85             dst->format = kRGBA_8888_ANPBitmapFormat;
    86             break;
    87         case SkBitmap::kRGB_565_Config:
    88             dst->format = kRGB_565_ANPBitmapFormat;
    89             break;
    90         default:
    91             SkDebugf("SkANP::SetBitmap - unsupported src.config %d\n", src.config());
    92             return false;
    93     }
    95     dst->width    = src.width();
    96     dst->height   = src.height();
    97     dst->rowBytes = src.rowBytes();
    98     return true;
    99 }
   101 void SkANP::InitEvent(ANPEvent* event, ANPEventType et) {
   102     event->inSize = sizeof(ANPEvent);
   103     event->eventType = et;
   104 }

mercurial