18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright 2008, The Android Open Source Project 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met: 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * * Redistributions of source code must retain the above copyright 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * notice, this list of conditions and the following disclaimer. 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * * Redistributions in binary form must reproduce the above copyright 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * documentation and/or other materials provided with the distribution. 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 163298a7d84b96ade73c6b170671711a8f2792ae59Steve Block * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// must include config.h first for webkit to fiddle with new/delete 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h" 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SkANP.h" 2922c64e5cc7b7c54cea1cf6cb3bb1021f072e365cGrace Kloba#include <wtf/CurrentTime.h> 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectSkRect* SkANP::SetRect(SkRect* dst, const ANPRectF& src) { 328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->set(SkFloatToScalar(src.left), 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkFloatToScalar(src.top), 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkFloatToScalar(src.right), 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkFloatToScalar(src.bottom)); 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return dst; 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectSkIRect* SkANP::SetRect(SkIRect* dst, const ANPRectI& src) { 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->set(src.left, src.top, src.right, src.bottom); 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return dst; 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectANPRectI* SkANP::SetRect(ANPRectI* dst, const SkIRect& src) { 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->left = src.fLeft; 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->top = src.fTop; 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->right = src.fRight; 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->bottom = src.fBottom; 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return dst; 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectANPRectF* SkANP::SetRect(ANPRectF* dst, const SkRect& src) { 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->left = SkScalarToFloat(src.fLeft); 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->top = SkScalarToFloat(src.fTop); 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->right = SkScalarToFloat(src.fRight); 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->bottom = SkScalarToFloat(src.fBottom); 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return dst; 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectSkBitmap* SkANP::SetBitmap(SkBitmap* dst, const ANPBitmap& src) { 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkBitmap::Config config = SkBitmap::kNo_Config; 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project switch (src.format) { 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case kRGBA_8888_ANPBitmapFormat: 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project config = SkBitmap::kARGB_8888_Config; 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case kRGB_565_ANPBitmapFormat: 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project config = SkBitmap::kRGB_565_Config; 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project default: 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->setConfig(config, src.width, src.height, src.rowBytes); 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->setPixels(src.baseAddr); 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return dst; 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool SkANP::SetBitmap(ANPBitmap* dst, const SkBitmap& src) { 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!(dst->baseAddr = src.getPixels())) { 818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkDebugf("SkANP::SetBitmap - getPixels() returned null\n"); 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return false; 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project switch (src.config()) { 868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case SkBitmap::kARGB_8888_Config: 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->format = kRGBA_8888_ANPBitmapFormat; 888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case SkBitmap::kRGB_565_Config: 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->format = kRGB_565_ANPBitmapFormat; 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project default: 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SkDebugf("SkANP::SetBitmap - unsupported src.config %d\n", src.config()); 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return false; 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->width = src.width(); 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->height = src.height(); 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project dst->rowBytes = src.rowBytes(); 1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return true; 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid SkANP::InitEvent(ANPEvent* event, ANPEventType et) { 1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project event->inSize = sizeof(ANPEvent); 1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project event->eventType = et; 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 107