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