Bumping manifests a=b2g-bump
[gecko.git] / other-licenses / skia-npapi / SkANP.cpp
blobdb9302bcdfad8d62fc2f28ef5f93727d37b81010
1 /*
2 * Copyright 2008, The Android Open Source Project
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.
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.
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;
37 SkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) {
38 dst->set(src.left, src.top, src.right, src.bottom);
39 return dst;
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;
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;
58 SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
59 SkColorType colorType = kUnknown_SkColorType;
61 switch (src.format) {
62 case kRGBA_8888_ANPBitmapFormat:
63 // Let Skia choose the correct colour type for us based on its
64 // endianness. This should be correct.
65 colorType = kN32_SkColorType;
66 break;
67 case kRGB_565_ANPBitmapFormat:
68 colorType = kRGB_565_SkColorType;
69 break;
70 default:
71 break;
74 SkImageInfo info = SkImageInfo::Make(src.width, src.height, colorType, kPremul_SkAlphaType);
75 dst->setInfo(info, src.rowBytes);
76 dst->setPixels(src.baseAddr);
77 return dst;
80 bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) {
81 if (!(dst->baseAddr = src.getPixels())) {
82 SkDebugf("SkANP::SetBitmap - getPixels() returned null\n");
83 return false;
86 switch (src.colorType()) {
87 case SkColorType::kRGBA_8888_SkColorType:
88 dst->format = kRGBA_8888_ANPBitmapFormat;
89 break;
90 case SkColorType::kRGB_565_SkColorType:
91 dst->format = kRGB_565_ANPBitmapFormat;
92 break;
93 default:
94 SkDebugf("SkANP::SetBitmap - unsupported src.colorType %d\n", src.colorType());
95 return false;
98 dst->width = src.width();
99 dst->height = src.height();
100 dst->rowBytes = src.rowBytes();
101 return true;
104 void SkANP::InitEvent(ANPEvent* event, ANPEventType et) {
105 event->inSize = sizeof(ANPEvent);
106 event->eventType = et;