1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/skia-npapi/ANPCanvas.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,193 @@ 1.4 +/* 1.5 + * Copyright 2008, The Android Open Source Project 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions 1.9 + * are met: 1.10 + * * Redistributions of source code must retain the above copyright 1.11 + * notice, this list of conditions and the following disclaimer. 1.12 + * * Redistributions in binary form must reproduce the above copyright 1.13 + * notice, this list of conditions and the following disclaimer in the 1.14 + * documentation and/or other materials provided with the distribution. 1.15 + * 1.16 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 1.17 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.18 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.19 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.20 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.21 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.22 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.23 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.24 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 + */ 1.28 + 1.29 +// must include config.h first for webkit to fiddle with new/delete 1.30 +#include "SkANP.h" 1.31 + 1.32 +static ANPCanvas* anp_newCanvas(const ANPBitmap* bitmap) { 1.33 + SkBitmap bm; 1.34 + return new ANPCanvas(*SkANP::SetBitmap(&bm, *bitmap)); 1.35 +} 1.36 + 1.37 +static void anp_deleteCanvas(ANPCanvas* canvas) { 1.38 + delete canvas; 1.39 +} 1.40 + 1.41 +static void anp_save(ANPCanvas* canvas) { 1.42 + canvas->skcanvas->save(); 1.43 +} 1.44 + 1.45 +static void anp_restore(ANPCanvas* canvas) { 1.46 + canvas->skcanvas->restore(); 1.47 +} 1.48 + 1.49 +static void anp_translate(ANPCanvas* canvas, float tx, float ty) { 1.50 + canvas->skcanvas->translate(SkFloatToScalar(tx), SkFloatToScalar(ty)); 1.51 +} 1.52 + 1.53 +static void anp_scale(ANPCanvas* canvas, float sx, float sy) { 1.54 + canvas->skcanvas->scale(SkFloatToScalar(sx), SkFloatToScalar(sy)); 1.55 +} 1.56 + 1.57 +static void anp_rotate(ANPCanvas* canvas, float degrees) { 1.58 + canvas->skcanvas->rotate(SkFloatToScalar(degrees)); 1.59 +} 1.60 + 1.61 +static void anp_skew(ANPCanvas* canvas, float kx, float ky) { 1.62 + canvas->skcanvas->skew(SkFloatToScalar(kx), SkFloatToScalar(ky)); 1.63 +} 1.64 + 1.65 +static void anp_clipRect(ANPCanvas* canvas, const ANPRectF* rect) { 1.66 + SkRect r; 1.67 + canvas->skcanvas->clipRect(*SkANP::SetRect(&r, *rect)); 1.68 +} 1.69 + 1.70 +static void anp_clipPath(ANPCanvas* canvas, const ANPPath* path) { 1.71 + canvas->skcanvas->clipPath(*path); 1.72 +} 1.73 +static void anp_concat(ANPCanvas* canvas, const ANPMatrix* matrix) { 1.74 + canvas->skcanvas->concat(*matrix); 1.75 +} 1.76 + 1.77 +static void anp_getTotalMatrix(ANPCanvas* canvas, ANPMatrix* matrix) { 1.78 + const SkMatrix& src = canvas->skcanvas->getTotalMatrix(); 1.79 + *matrix = *reinterpret_cast<const ANPMatrix*>(&src); 1.80 +} 1.81 + 1.82 +static bool anp_getLocalClipBounds(ANPCanvas* canvas, ANPRectF* r, 1.83 + bool antialias) { 1.84 + SkRect bounds; 1.85 + if (canvas->skcanvas->getClipBounds(&bounds)) { 1.86 + SkANP::SetRect(r, bounds); 1.87 + return true; 1.88 + } 1.89 + return false; 1.90 +} 1.91 + 1.92 +static bool anp_getDeviceClipBounds(ANPCanvas* canvas, ANPRectI* r) { 1.93 + const SkRegion& clip = canvas->skcanvas->getTotalClip(); 1.94 + if (!clip.isEmpty()) { 1.95 + SkANP::SetRect(r, clip.getBounds()); 1.96 + return true; 1.97 + } 1.98 + return false; 1.99 +} 1.100 + 1.101 +static void anp_drawColor(ANPCanvas* canvas, ANPColor color) { 1.102 + canvas->skcanvas->drawColor(color); 1.103 +} 1.104 + 1.105 +static void anp_drawPaint(ANPCanvas* canvas, const ANPPaint* paint) { 1.106 + canvas->skcanvas->drawPaint(*paint); 1.107 +} 1.108 + 1.109 +static void anp_drawLine(ANPCanvas* canvas, float x0, float y0, 1.110 + float x1, float y1, const ANPPaint* paint) { 1.111 + canvas->skcanvas->drawLine(SkFloatToScalar(x0), SkFloatToScalar(y0), 1.112 + SkFloatToScalar(x1), SkFloatToScalar(y1), *paint); 1.113 +} 1.114 + 1.115 +static void anp_drawRect(ANPCanvas* canvas, const ANPRectF* rect, 1.116 + const ANPPaint* paint) { 1.117 + SkRect r; 1.118 + canvas->skcanvas->drawRect(*SkANP::SetRect(&r, *rect), *paint); 1.119 +} 1.120 + 1.121 +static void anp_drawOval(ANPCanvas* canvas, const ANPRectF* rect, 1.122 + const ANPPaint* paint) { 1.123 + SkRect r; 1.124 + canvas->skcanvas->drawOval(*SkANP::SetRect(&r, *rect), *paint); 1.125 +} 1.126 + 1.127 +static void anp_drawPath(ANPCanvas* canvas, const ANPPath* path, 1.128 + const ANPPaint* paint) { 1.129 + canvas->skcanvas->drawPath(*path, *paint); 1.130 +} 1.131 + 1.132 +static void anp_drawText(ANPCanvas* canvas, const void* text, uint32_t length, 1.133 + float x, float y, const ANPPaint* paint) { 1.134 + canvas->skcanvas->drawText(text, length, 1.135 + SkFloatToScalar(x), SkFloatToScalar(y), 1.136 + *paint); 1.137 +} 1.138 + 1.139 +static void anp_drawPosText(ANPCanvas* canvas, const void* text, 1.140 + uint32_t byteLength, const float xy[], const ANPPaint* paint) { 1.141 + canvas->skcanvas->drawPosText(text, byteLength, 1.142 + reinterpret_cast<const SkPoint*>(xy), *paint); 1.143 +} 1.144 + 1.145 +static void anp_drawBitmap(ANPCanvas* canvas, const ANPBitmap* bitmap, 1.146 + float x, float y, const ANPPaint* paint) { 1.147 + SkBitmap bm; 1.148 + canvas->skcanvas->drawBitmap(*SkANP::SetBitmap(&bm, *bitmap), 1.149 + SkFloatToScalar(x), SkFloatToScalar(y), 1.150 + paint); 1.151 +} 1.152 + 1.153 +static void anp_drawBitmapRect(ANPCanvas* canvas, const ANPBitmap* bitmap, 1.154 + const ANPRectI* src, const ANPRectF* dst, 1.155 + const ANPPaint* paint) { 1.156 + SkBitmap bm; 1.157 + SkRect dstR; 1.158 + SkIRect srcR, *srcPtr = NULL; 1.159 + 1.160 + if (src) { 1.161 + srcPtr = SkANP::SetRect(&srcR, *src); 1.162 + } 1.163 + canvas->skcanvas->drawBitmapRect(*SkANP::SetBitmap(&bm, *bitmap), srcPtr, 1.164 + *SkANP::SetRect(&dstR, *dst), paint); 1.165 +} 1.166 + 1.167 +/////////////////////////////////////////////////////////////////////////////// 1.168 + 1.169 +#define ASSIGN(obj, name) (obj)->name = anp_##name 1.170 + 1.171 +void InitCanvasInterface(ANPCanvasInterfaceV0* i) { 1.172 + ASSIGN(i, newCanvas); 1.173 + ASSIGN(i, deleteCanvas); 1.174 + ASSIGN(i, save); 1.175 + ASSIGN(i, restore); 1.176 + ASSIGN(i, translate); 1.177 + ASSIGN(i, scale); 1.178 + ASSIGN(i, rotate); 1.179 + ASSIGN(i, skew); 1.180 + ASSIGN(i, clipRect); 1.181 + ASSIGN(i, clipPath); 1.182 + ASSIGN(i, concat); 1.183 + ASSIGN(i, getTotalMatrix); 1.184 + ASSIGN(i, getLocalClipBounds); 1.185 + ASSIGN(i, getDeviceClipBounds); 1.186 + ASSIGN(i, drawColor); 1.187 + ASSIGN(i, drawPaint); 1.188 + ASSIGN(i, drawLine); 1.189 + ASSIGN(i, drawRect); 1.190 + ASSIGN(i, drawOval); 1.191 + ASSIGN(i, drawPath); 1.192 + ASSIGN(i, drawText); 1.193 + ASSIGN(i, drawPosText); 1.194 + ASSIGN(i, drawBitmap); 1.195 + ASSIGN(i, drawBitmapRect); 1.196 +}