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 APPLE COMPUTER, INC. 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 */
25
26 // must include config.h first for webkit to fiddle with new/delete
27 #include "config.h"
28 #include "SkANP.h"
29
SetRect(SkRect * dst,const ANPRectF & src)30 SkRect* SkANP::SetRect(SkRect* dst, const ANPRectF& src) {
31 dst->set(SkFloatToScalar(src.left),
32 SkFloatToScalar(src.top),
33 SkFloatToScalar(src.right),
34 SkFloatToScalar(src.bottom));
35 return dst;
36 }
37
SetRect(SkIRect * dst,const ANPRectI & src)38 SkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) {
39 dst->set(src.left, src.top, src.right, src.bottom);
40 return dst;
41 }
42
SetRect(ANPRectI * dst,const SkIRect & src)43 ANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) {
44 dst->left = src.fLeft;
45 dst->top = src.fTop;
46 dst->right = src.fRight;
47 dst->bottom = src.fBottom;
48 return dst;
49 }
50
SetRect(ANPRectF * dst,const SkRect & src)51 ANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) {
52 dst->left = SkScalarToFloat(src.fLeft);
53 dst->top = SkScalarToFloat(src.fTop);
54 dst->right = SkScalarToFloat(src.fRight);
55 dst->bottom = SkScalarToFloat(src.fBottom);
56 return dst;
57 }
58
SetBitmap(SkBitmap * dst,const ANPBitmap & src)59 SkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) {
60 SkBitmap::Config config = SkBitmap::kNo_Config;
61
62 switch (src.format) {
63 case kRGBA_8888_ANPBitmapFormat:
64 config = SkBitmap::kARGB_8888_Config;
65 break;
66 case kRGB_565_ANPBitmapFormat:
67 config = SkBitmap::kRGB_565_Config;
68 break;
69 default:
70 break;
71 }
72
73 dst->setConfig(config, src.width, src.height, src.rowBytes);
74 dst->setPixels(src.baseAddr);
75 return dst;
76 }
77
SetBitmap(ANPBitmap * dst,const SkBitmap & src)78 bool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) {
79 if (!(dst->baseAddr = src.getPixels())) {
80 SkDebugf("SkANP::SetBitmap - getPixels() returned null\n");
81 return false;
82 }
83
84 switch (src.config()) {
85 case SkBitmap::kARGB_8888_Config:
86 dst->format = kRGBA_8888_ANPBitmapFormat;
87 break;
88 case SkBitmap::kRGB_565_Config:
89 dst->format = kRGB_565_ANPBitmapFormat;
90 break;
91 default:
92 SkDebugf("SkANP::SetBitmap - unsupported src.config %d\n", src.config());
93 return false;
94 }
95
96 dst->width = src.width();
97 dst->height = src.height();
98 dst->rowBytes = src.rowBytes();
99 return true;
100 }
101
InitEvent(ANPEvent * event,ANPEventType et)102 void SkANP::InitEvent(ANPEvent* event, ANPEventType et) {
103 event->inSize = sizeof(ANPEvent);
104 event->eventType = et;
105 }
106
107