other-licenses/skia-npapi/SkANP.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial