SkDraw.cpp revision ecadf99c8450646dfd9c2754f3e845245beab8b6
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBounder.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDevice.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMaskFilter.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h" 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRasterizer.h" 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScan.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStroke.h" 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTemplatesPriv.h" 2432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com#include "SkTLazy.h" 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAutoKern.h" 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmapProcShader.h" 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawProcs.h" 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//#define TRACE_BITMAP_DRAWS 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define kBlitterStorageLongCount (sizeof(SkBitmapProcShader) >> 2) 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 35fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com/** Helper for allocating small blitters on the stack. 36fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com */ 3740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBlitterChoose : SkNoncopyable { 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 391d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose() { 401d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = NULL; 411d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = SkBlitter::Choose(device, matrix, paint, 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage)); 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 471d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBlitterChoose(); 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* operator->() { return fBlitter; } 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* get() const { return fBlitter; } 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 531d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com void choose(const SkBitmap& device, const SkMatrix& matrix, 541d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com const SkPaint& paint) { 551d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkASSERT(!fBlitter); 561d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = SkBlitter::Choose(device, matrix, paint, 571d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fStorage, sizeof(fStorage)); 581d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 591d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* fBlitter; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fStorage[kBlitterStorageLongCount]; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAutoBlitterChoose::~SkAutoBlitterChoose() { 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)fBlitter == (void*)fStorage) { 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter->~SkBlitter(); 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(fBlitter); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com/** 7440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * Since we are providing the storage for the shader (to avoid the perf cost 7540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * of calling new) we insist that in our destructor we can account for all 7640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * owners of the shader. 7740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com */ 7840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBitmapShaderInstall : SkNoncopyable { 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 8040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) 8140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com : fPaint(paint) /* makes a copy of the paint */ { 8240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(SkShader::CreateBitmapShader(src, 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage))); 8540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // we deliberately left the shader with an owner-count of 2 8640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == fPaint.getShader()->getRefCnt()); 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8882065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBitmapShaderInstall() { 9040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkShader* shader = fPaint.getShader(); 9140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // since we manually destroy shader, we insist that owners == 2 9240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == shader->getRefCnt()); 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(NULL); // unref the shader by 1 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // now destroy to take care of the 2nd owner-count 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)shader == (void*)fStorage) { 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->~SkShader(); 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(shader); 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10382065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 10440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // return the new paint that has the shader applied 10540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& paintWithShader() const { return fPaint; } 10682065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 10840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint fPaint; // copy of caller's paint (which we then modify) 10940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com uint32_t fStorage[kBlitterStorageLongCount]; 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 114f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comSkDraw::SkDraw() { 115f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com sk_bzero(this, sizeof(*this)); 116f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 117f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw::SkDraw(const SkDraw& src) { 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memcpy(this, &src, sizeof(*this)); 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*BitmapXferProc)(void* pixels, size_t bytes, uint32_t data); 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Clear_BitmapXferProc(void* pixels, size_t bytes, uint32_t) { 1274516f4786f5dda1b86a8f825b9e8e910d9c2363creed@android.com sk_bzero(pixels, bytes); 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Dst_BitmapXferProc(void*, size_t, uint32_t data) {} 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D32_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset32((uint32_t*)pixels, data, bytes >> 2); 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D16_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset16((uint16_t*)pixels, data, bytes >> 1); 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(pixels, data, bytes); 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap, 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t* data) { 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // todo: we can apply colorfilter up front if no shader, so we wouldn't 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to abort this fastpath 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getShader() || paint.getColorFilter()) { 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 153845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode; 154845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (!SkXfermode::IsMode(paint.getXfermode(), &mode)) { 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 157a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColor color = paint.getColor(); 159a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // collaps modes based on color... 161845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (SkXfermode::kSrcOver_Mode == mode) { 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned alpha = SkColorGetA(color); 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == alpha) { 164845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kDst_Mode; 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (0xFF == alpha) { 166845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kSrc_Mode; 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 169a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 171845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kClear_Mode: 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Clear_BitmapXferProc\n"); 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Clear_BitmapXferProc; // ignore data 174845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kDst_Mode: 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Dst_BitmapXferProc\n"); 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Dst_BitmapXferProc; // ignore data 177845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kSrc_Mode: { 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 179a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com should I worry about dithering for the lower depths? 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor pmc = SkPreMultiplyColor(color); 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = pmc; 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D32_Src_BitmapXferProc\n"); 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D32_Src_BitmapXferProc; 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel4444(pmc); 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel16(pmc); 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkGetPackedA32(pmc); 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- DA8_Src_BitmapXferProc\n"); 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return DA8_Src_BitmapXferProc; 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com BitmapXferProc proc, uint32_t procData) { 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int shiftPerPixel; 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 2; 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 1; 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 0; 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"Can't use xferproc on this config"); 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t* pixels = (uint8_t*)bitmap.getPixels(); 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pixels); 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t rowBytes = bitmap.rowBytes(); 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const int widthBytes = rect.width() << shiftPerPixel; 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // skip down to the first scanline and X position 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rect.fTop * rowBytes + (rect.fLeft << shiftPerPixel); 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int scans = rect.height() - 1; scans >= 0; --scans) { 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(pixels, widthBytes, procData); 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rowBytes; 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPaint(const SkPaint& paint) const { 251f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty()) { 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devRect; 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.set(0, 0, fBitmap->width(), fBitmap->height()); 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(devRect)) { 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 262a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* If we don't have a shader (i.e. we're just a solid color) we may 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be faster to operate directly on the device bitmap, rather than invoking 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a blitter. Esp. true for xfermodes, which require a colorshader to be 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com present, which is just redundant work. Since we're drawing everywhere 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in the clip, we don't have to worry about antialiasing. 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t procData = 0; // to avoid the warning 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData); 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (proc) { 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (D_Dst_BitmapXferProc == proc) { // nothing to do 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 275a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Iterator iter(*fClip); 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (!iter.done()) { 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData); 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com iter.next(); 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // normal case: use a blitter 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillIRect(devRect, fClip, blitter.get()); 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct PtProcRec { 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas::PointMode fMode; 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* fPaint; 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* fClip; 294a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // computed values 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fRadius; 297a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const PtProcRec&, const SkPoint devPts[], int count, 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool init(SkCanvas::PointMode, const SkPaint&, const SkMatrix* matrix, 302a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com const SkRegion* clip); 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkBlitter* blitter); 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(rec.fClip->isRect()); 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& r = rec.fClip->getBounds(); 310a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_16_hair_proc(const PtProcRec& rec, 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint devPts[], int count, 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter) { 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(rec.fClip->isRect()); 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& r = rec.fClip->getBounds(); 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap); 328a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint16_t* addr = bitmap->getAddr16(0, 0); 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rb = bitmap->rowBytes(); 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// *bitmap->getAddr16(x, y) = SkToU16(value); 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ((uint16_t*)((char*)addr + y * rb))[x] = SkToU16(value); 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (rec.fClip->contains(x, y)) { 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// aa versions 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// square procs (strokeWidth > 0 but matrix is square-scale (sx == sy) 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[], 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 391a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 397a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillXRect(r, rec.fClip, blitter); 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[], 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 408a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 414a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiFillXRect(r, rec.fClip, blitter); 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 419b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com// If this guy returns true, then chooseProc() must return a valid proc 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint, 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix, const SkRegion* clip) { 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect()) { 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width = paint.getStrokeWidth(); 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == width) { 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = clip; 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SK_Fixed1 >> 1; 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 433b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com if (paint.getStrokeCap() != SkPaint::kRound_Cap && 434b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com matrix->rectStaysRect() && SkCanvas::kPoints_PointMode == mode) { 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = matrix->get(SkMatrix::kMScaleX); 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = matrix->get(SkMatrix::kMScaleY); 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkScalarNearlyZero(sx - sy)) { 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (sx < 0) { 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sx = -sx; 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = clip; 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comPtProcRec::Proc PtProcRec::chooseProc(SkBlitter* blitter) { 453b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com Proc proc = NULL; 454a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // for our arrays 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == SkCanvas::kPoints_PointMode); 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == SkCanvas::kLines_PointMode); 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(2 == SkCanvas::kPolygon_PointMode); 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)fMode <= (unsigned)SkCanvas::kPolygon_PointMode); 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // first check for hairlines 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == fPaint->getStrokeWidth()) { 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const Proc gAAProcs[] = { 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa_square_proc, aa_line_hair_proc, aa_poly_hair_proc 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gAAProcs[fMode]; 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bm = blitter->justAnOpaqueColor(&value); 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bm && bm->config() == SkBitmap::kRGB_565_Config) { 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_16_hair_proc; 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_hair_proc; 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static Proc gBWProcs[] = { 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gBWProcs[fMode]; 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 484b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) { 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(SkCanvas::kPoints_PointMode == fMode); 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = aa_square_proc; 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_square_proc; 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return proc; 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool bounder_points(SkBounder* bounder, SkCanvas::PointMode mode, 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t count, const SkPoint pts[], 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, const SkMatrix& matrix) { 4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ibounds; 4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar inset = paint.getStrokeWidth(); 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(pts, count); 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.inset(-inset, -inset); 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapRect(&bounds); 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&ibounds); 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return bounder->doIRect(ibounds); 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// each of these costs 8-bytes of stack space, so don't make it too large 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// must be even for lines/polygon to work 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define MAX_DEV_PTS 32 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count, 515f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPoint pts[], const SkPaint& paint, 516f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com bool forceUseDevice) const { 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we're in lines mode, force count to be even 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kLines_PointMode == mode) { 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count &= ~(size_t)1; 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((long)count <= 0) { 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 525a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pts != NULL); 527f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 528a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 535fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (fBounder) { 536fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (!bounder_points(fBounder, mode, count, pts, paint, *fMatrix)) { 537fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 538fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 539fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 540fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // clear the bounder and call this again, so we don't invoke the bounder 541fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // later if we happen to call ourselves for drawRect, drawPath, etc. 542fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com SkDraw noBounder(*this); 543fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.fBounder = NULL; 544fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.drawPoints(mode, count, pts, paint, forceUseDevice); 545fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 546fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 547fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 5488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec rec; 549f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (!forceUseDevice && rec.init(mode, paint, fMatrix, fClip)) { 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint devPts[MAX_DEV_PTS]; 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* bltr = blitter.get(); 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec::Proc proc = rec.chooseProc(bltr); 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we have to back up subsequent passes if we're in polygon mode 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t backup = (SkCanvas::kPolygon_PointMode == mode); 558a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t n = count; 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (n > MAX_DEV_PTS) { 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com n = MAX_DEV_PTS; 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix->mapPoints(devPts, pts, n); 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(rec, devPts, n, bltr); 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pts += n - backup; 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(count >= n); 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= n; 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count > 0) { 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count += backup; 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (count != 0); 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPoints_PointMode: { 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // temporarily mark the paint as filling. 57740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint newPaint(paint); 57840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com newPaint.setStyle(SkPaint::kFill_Style); 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 58040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkScalar width = newPaint.getStrokeWidth(); 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar radius = SkScalarHalf(width); 582a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 58340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix preMatrix; 586a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.addCircle(0, 0, radius); 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preMatrix.setTranslate(pts[i].fX, pts[i].fY); 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // pass true for the last point, since we can modify 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // then path then 592f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 59340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawPath(*this, path, newPaint, &preMatrix, 594f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com (count-1) == i); 595f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 59640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawPath(path, newPaint, &preMatrix, 59740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (count-1) == i); 598f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 602a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = pts[i].fX - radius; 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = pts[i].fY - radius; 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = r.fLeft + width; 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = r.fTop + width; 608f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 60940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawRect(*this, r, newPaint); 610f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 61140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawRect(r, newPaint); 612f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kLines_PointMode: 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPolygon_PointMode: { 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= 1; 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStyle(SkPaint::kStroke_Style); 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i += inc) { 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.moveTo(pts[i]); 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.lineTo(pts[i+1]); 627f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 628f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, path, p, NULL, true); 629f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 630f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(path, p, NULL, true); 631f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.rewind(); 6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_lefttop(SkRect* r) { 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkPoint*)(void*)r; 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_rightbottom(SkRect* r) { 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return ((SkPoint*)(void*)r) + 1; 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 648761fb62b0eb174783316d2a8b933fba896ca6355reed@google.comstatic bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, 649761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint* strokeSize) { 650761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com if (SkPaint::kMiter_Join != paint.getStrokeJoin() || 651761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com paint.getStrokeMiter() < SK_ScalarSqrt2) { 652761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return false; 653761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com } 65462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 655761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkASSERT(matrix.rectStaysRect()); 656761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() }; 657761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com matrix.mapVectors(strokeSize, &pt, 1); 6586115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fX = SkScalarAbs(strokeSize->fX); 6596115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fY = SkScalarAbs(strokeSize->fY); 660761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return true; 6617ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org} 6627ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 66362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comSkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, 66462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const SkMatrix& matrix, 66562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint* strokeSize) { 6667ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org RectType rtype; 6677ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org const SkScalar width = paint.getStrokeWidth(); 66862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const bool zeroWidth = (0 == width); 6697ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::Style style = paint.getStyle(); 67062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) { 6727ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org style = SkPaint::kFill_Style; 6737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 67462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect() || paint.getMaskFilter() || 67662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com paint.getRasterizer() || !matrix.rectStaysRect() || 6777ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::kStrokeAndFill_Style == style) { 67862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 67962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (SkPaint::kFill_Style == style) { 6807ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kFill_RectType; 6817ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else if (zeroWidth) { 6827ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kHair_RectType; 68362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (easy_rect_join(paint, matrix, strokeSize)) { 6847ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kStroke_RectType; 6857ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 6867ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kPath_RectType; 6877ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 68862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return rtype; 68962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com} 69062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 69140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comstatic SkPoint* rect_points(SkRect& r, int index) { 69240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT((unsigned)index < 2); 69340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com return &((SkPoint*)(void*)&r)[index]; 69440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com} 69540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com 69662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comvoid SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const { 69762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkDEBUGCODE(this->validate();) 6987ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 69962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com // nothing to draw 70062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (fClip->isEmpty() || 70162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 70262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return; 70362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 70462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 70562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint strokeSize; 70662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); 70762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 70862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#ifdef SK_DISABLE_FAST_AA_STROKE_RECT 70962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (kStroke_RectType == rtype && paint.isAntiAlias()) { 71062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 71162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 71262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#endif 71362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 7147ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (kPath_RectType == rtype) { 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.addRect(rect); 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.setFillType(SkPath::kWinding_FillType); 718187d5595901d1120d9425851e5afdd773f574502reed@android.com this->drawPath(tmp, paint, NULL, true); 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix = *fMatrix; 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect devRect; 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform rect into devRect 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fLeft, rect.fTop, rect_points(devRect, 0)); 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fRight, rect.fBottom, rect_points(devRect, 1)); 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.sort(); 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doRect(devRect, paint)) { 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // look for the quick exit, before we build a blitter 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.roundOut(&ir); 74055e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com if (paint.getStyle() != SkPaint::kFill_Style) { 74155e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com // extra space for hairlines 74255e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com ir.inset(-1, -1); 74355e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com } 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(ir)) 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitterStorage(*fBitmap, matrix, paint); 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = blitterStorage.get(); 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* clip = fClip; 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 752b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter 753b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // case we are also hairline (if we've gotten to here), which devolves to 754b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // effectively just kFill 7557ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org switch (rtype) { 7567ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kFill_RectType: 7577ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7587ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiFillRect(devRect, clip, blitter); 7597ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7607ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::FillRect(devRect, clip, blitter); 7617ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7627ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7637ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kStroke_RectType: 7647ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 765761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::AntiFrameRect(devRect, strokeSize, clip, blitter); 7667ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 767761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::FrameRect(devRect, strokeSize, clip, blitter); 7687ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7697ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7707ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kHair_RectType: 7717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7727ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiHairRect(devRect, clip, blitter); 7737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7747ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::HairRect(devRect, clip, blitter); 7757ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7767ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7777ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org default: 7787ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkASSERT(!"bad rtype"); 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (srcM.fBounds.isEmpty()) { 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask dstM; 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMask* mask = &srcM; 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstM.fImage = NULL; 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMaskImage ami(&dstM, false); 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getMaskFilter() && 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask = &dstM; 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(mask->fBounds)) { 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitMaskRegion(*mask, *fClip); 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 807ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.comstatic SkScalar fast_len(const SkVector& vec) { 808ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar x = SkScalarAbs(vec.fX); 809ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar y = SkScalarAbs(vec.fY); 810ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com if (x < y) { 811ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkTSwap(x, y); 812ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 813ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return x + SkScalarHalf(y); 814ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 815ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 816ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.comstatic bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) { 817ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkXfermode::Coeff dc; 818ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!SkXfermode::AsCoeff(xfer, NULL, &dc)) { 819ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 820ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 821ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 822ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com switch (dc) { 823ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kOne_Coeff: 824ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISA_Coeff: 825ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISC_Coeff: 826ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 827ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com default: 828ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 829ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 830ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com} 831ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 832ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.combool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, 833ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha* newAlpha) { 834ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkASSERT(newAlpha); 835ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkPaint::kStroke_Style != paint.getStyle()) { 836ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 837ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 838ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar strokeWidth = paint.getStrokeWidth(); 839ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (0 == strokeWidth) { 840ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = paint.getAlpha(); 841ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 842ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 843ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 844ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // if we get here, we need to try to fake a thick-stroke with a modulated 845ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // hairline 846ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 847ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!paint.isAntiAlias()) { 848ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 849ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 850ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!xfermodeSupportsCoverageAsAlpha(paint.getXfermode())) { 851ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 852ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 8538d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com if (matrix.hasPerspective()) { 854ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 855ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 856ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 857ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkVector src[2], dst[2]; 858ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[0].set(strokeWidth, 0); 859ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[1].set(0, strokeWidth); 860ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com matrix.mapVectors(dst, src, 2); 861ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len0 = fast_len(dst[0]); 862ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len1 = fast_len(dst[1]); 863652807bbc8c57e5fa9622126b51fd369f5c67935agl@chromium.org if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { 864ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar modulate = SkScalarAve(len0, len1); 865ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = SkToU8(SkScalarRoundToInt(modulate * paint.getAlpha())); 866ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return true; 867ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 868ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 869ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 870ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 87132e5d97ccf60f859db063ebd6e903c362e625767reed@google.comvoid SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* prePathMatrix, bool pathIsMutable) const { 873f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 87732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* pathPtr = (SkPath*)&origSrcPath; 8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool doFill = true; 8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmpPath; 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix tmpMatrix; 8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (prePathMatrix) { 88832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style || 88932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getRasterizer()) { 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* result = pathPtr; 891a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!pathIsMutable) { 8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result = &tmpPath; 8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathIsMutable = true; 8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*prePathMatrix, result); 8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = result; 8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!tmpMatrix.setConcat(*matrix, *prePathMatrix)) { 9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overflow 9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix = &tmpMatrix; 9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // at this point we're done with prePathMatrix 9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) 908a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 90932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com const SkPaint* paint = &origPaint; 91032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkTLazy<SkPaint> lazyPaint; 911a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 912ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com { 913ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha newAlpha; 914ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkDrawTreatAsHairline(origPaint, *matrix, &newAlpha)) { 91532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.set(origPaint); 916ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com lazyPaint.get()->setAlpha(newAlpha); 91732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.get()->setStrokeWidth(0); 91832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint = lazyPaint.get(); 9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 921a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 92232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { 92332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com doFill = paint->getFillPath(*pathPtr, &tmpPath); 9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = &tmpPath; 9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 926a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 92732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()) { 9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 92932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, 93032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com &fClip->getBounds(), paint->getMaskFilter(), &mask, 9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::kComputeBoundsAndRenderImage_CreateMode)) { 93232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com this->drawDevMask(mask, *paint); 9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::FreeImage(mask.fImage); 9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // avoid possibly allocating a new path in transform if we can 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; 9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform the path into device space 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*matrix, devPathPtr); 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 94432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint); 9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // how does filterPath() know to fill or hairline the path??? <mrr> 94732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getMaskFilter() && 94832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fClip, 94932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com fBounder, blitter.get())) { 9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // filterPath() called the blitter, so we're done 9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 95332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (fBounder && !fBounder->doPath(*devPathPtr, *paint, doFill)) { 9548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 95832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiFillPath(*devPathPtr, *fClip, blitter.get()); 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillPath(*devPathPtr, *fClip, blitter.get()); 9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 96432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairPath(*devPathPtr, fClip, blitter.get()); 9668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairPath(*devPathPtr, fClip, blitter.get()); 9688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9720baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com/** For the purposes of drawing bitmaps, if a matrix is "almost" translate 9730baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com go ahead and treat it as if it were, so that subsequent code can go fast. 9740baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com */ 9750baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.comstatic bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { 9760baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkMatrix::TypeMask mask = matrix.getType(); 9770baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com 9780baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 9790baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return false; 9800baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9810baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & SkMatrix::kScale_Mask) { 9820baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sx = matrix[SkMatrix::kMScaleX]; 9830baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sy = matrix[SkMatrix::kMScaleY]; 9840baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int w = bitmap.width(); 9850baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int h = bitmap.height(); 9860baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w))); 9870baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h))); 9880baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return sw == w && sh == h; 9890baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9900baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com // if we got here, we're either kTranslate_Mask or identity 9910baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return true; 9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, 9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap.getConfig() == SkBitmap::kA8_Config); 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 998a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com if (just_translate(*fMatrix, bitmap)) { 9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(fMatrix->getTranslateX()); 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(fMatrix->getTranslateY()); 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = bitmap.rowBytes(); 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = bitmap.getAddr8(0, 0); 1007a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // need to xform the bitmap first 10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 1012a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, 10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); 10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapRect(&r); 10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.round(&mask.fBounds); 1017a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // set the mask's bounds to the transformed bitmap-bounds, 10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // clipped to the actual device 10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devBounds; 10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); 10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need intersect(l, t, r, b) on irect 10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!mask.fBounds.intersect(devBounds)) { 10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1028543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com 10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = SkAlign4(mask.fBounds.width()); 1031543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask.computeImageSize(); 1032543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 1033543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // the mask is too big to allocated, draw nothing 1034543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return; 1035543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 10368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // allocate (and clear) our temp buffer to hold the transformed bitmap 10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMalloc storage(size); 10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)storage.get(); 10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask.fImage, 0, size); 1041a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now draw our bitmap(src) into mask(dst), transformed by the matrix 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap device; 10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), 10468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.height(), mask.fRowBytes); 10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setPixels(mask.fImage); 1048a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas c(device); 10508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need the unclipped top/left for the translate 10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.translate(-SkIntToScalar(mask.fBounds.fLeft), 10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.concat(*fMatrix); 10543469c76c40790b409621fd7eff34f56240718549reed@android.com 10553469c76c40790b409621fd7eff34f56240718549reed@android.com // We can't call drawBitmap, or we'll infinitely recurse. Instead 1056fb12c3e6ba84f95dc15fbaddc239dede0ba1d60ereed@android.com // we manually build a shader and draw that into our new mask 10573469c76c40790b409621fd7eff34f56240718549reed@android.com SkPaint tmpPaint; 10583469c76c40790b409621fd7eff34f56240718549reed@android.com tmpPaint.setFlags(paint.getFlags()); 105940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, tmpPaint); 10603469c76c40790b409621fd7eff34f56240718549reed@android.com SkRect rr; 10613469c76c40790b409621fd7eff34f56240718549reed@android.com rr.set(0, 0, SkIntToScalar(bitmap.width()), 10623469c76c40790b409621fd7eff34f56240718549reed@android.com SkIntToScalar(bitmap.height())); 106340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com c.drawRect(rr, install.paintWithShader()); 10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& m, const SkRegion& c, 10708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& srcR) { 10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect dstR; 10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devIR; 1073a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.mapRect(&dstR, srcR); 1075a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com dstR.roundOut(&devIR); 10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return c.quickReject(devIR); 10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& matrix, const SkRegion& clip, 10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int width, int height) { 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return clipped_out(matrix, clip, r); 10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 108740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1088f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 10918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 10928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 10938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.getConfig() == SkBitmap::kNo_Config || 109440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 10958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1097a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1098a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#ifndef SK_ALLOW_OVER_32K_BITMAPS 10998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // run away on too-big bitmaps for now (exceed 16.16) 11008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.width() > 32767 || bitmap.height() > 32767) { 11018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1103a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#endif 1104a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 110540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 110640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 1107a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 11098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!matrix.setConcat(*fMatrix, prematrix)) { 11108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (clipped_out(matrix, *fClip, bitmap.width(), bitmap.height())) { 11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1117218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (fBounder && just_translate(matrix, bitmap)) { 1118218521e15706c4377b1be49d931c4d7c8d597445reed@android.com SkIRect ir; 1119218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t ix = SkScalarRound(matrix.getTranslateX()); 1120218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t iy = SkScalarRound(matrix.getTranslateY()); 1121218521e15706c4377b1be49d931c4d7c8d597445reed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1122218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (!fBounder->doIRect(ir)) { 1123218521e15706c4377b1be49d931c4d7c8d597445reed@android.com return; 1124218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1125218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1126218521e15706c4377b1be49d931c4d7c8d597445reed@android.com 1127218521e15706c4377b1be49d931c4d7c8d597445reed@android.com // only lock the pixels if we passed the clip and bounder tests 11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoLockPixels alp(bitmap); 11298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // after the lock, check if we are valid 11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!bitmap.readyToDraw()) { 11318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11340baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (bitmap.getConfig() != SkBitmap::kA8_Config && 11350baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com just_translate(matrix, bitmap)) { 11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(matrix.getTranslateX()); 11378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(matrix.getTranslateY()); 11388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ix, iy, storage, sizeof(storage)); 11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 11468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, ir); 11488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 11498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if 0 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("---- MISSING sprite case: config=%d [%d %d], device=%d, xfer=%p, alpha=0x%X colorFilter=%p\n", 11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.config(), bitmap.width(), bitmap.height(), fBitmap->config(), 11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getXfermode(), paint.getAlpha(), paint.getColorFilter()); 11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1162a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now make a temp draw on the stack, and use it 11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // 11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 11668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 1167a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.getConfig() == SkBitmap::kA8_Config) { 11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawBitmapAsMask(bitmap, paint); 11708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 117140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(bitmap.width()), 11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.height())); 1176a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this ok if paint has a rasterizer? 117740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, install.paintWithShader()); 11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 118240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1183f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 1184a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 11868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 11888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.getConfig() == SkBitmap::kNo_Config || 118940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 11908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect bounds; 11948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); 11958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(bounds)) { 11978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // nothing to draw 11988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 120040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 120140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 12028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == paint.getColorFilter()) { 12048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 12058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x, y, storage, sizeof(storage)); 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 12098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(bounds)) { 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, bounds); 12168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 12178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 12198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 12208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 122640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 122740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& shaderPaint = install.paintWithShader(); 12288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 12318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // get a scalar version of our rect 12338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(bounds); 12348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // tell the shader our offset 12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(r.fLeft, r.fTop); 123740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com shaderPaint.getShader()->setLocalMatrix(matrix); 1238a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 12408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.reset(); 12418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 12428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // call ourself with a rect 1243a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this OK if paint has a rasterizer? 124440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, shaderPaint); 12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 12488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalerContext.h" 12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGlyphCache.h" 12518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, 12548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char text[], size_t byteLength, SkVector* stopVector) { 12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = 0, y = 0; 12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 1259a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 12618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // don't need x, y here, since all subpixel variants will have the 12628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // same advance 12638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 12648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += autokern.adjust(glyph) + glyph.fAdvanceX; 12668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y += glyph.fAdvanceY; 12678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); 12698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(text == stop); 12718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText_asPaths(const char text[], size_t byteLength, 12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, 12758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 1276f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setScale(iter.getPathScale(), iter.getPathScale()); 12828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(x, y); 12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos, prevXPos = 0; 12868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(xpos - prevXPos, 0); 1289f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPaint& pnt = iter.getPaint(); 1290f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1291f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, *iterPath, pnt, &matrix, false); 1292f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1293f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(*iterPath, pnt, &matrix, false); 1294f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com prevXPos = xpos; 12968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// disable warning : local variable used without having been initialized 1300a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#if defined _WIN32 && _MSC_VER >= 1300 13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( push ) 13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( disable : 4701 ) 13038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RectClip(const SkDraw1Glyph& state, 1308f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1309f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1310f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1311f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClip->isRect()); 13148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClipBounds == state.fClip->getBounds()); 13168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int right = left + glyph.fWidth; 13218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int bottom = top + glyph.fHeight; 13228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect storage; 13258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds = &mask.fBounds; 13268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, right, bottom); 13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // this extra test is worth it, assuming that most of the time it succeeds 13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // since we can avoid writing to storage 13318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { 13328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) 13338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds = &storage; 13358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1336a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1337a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com uint8_t* aa = (uint8_t*)glyph.fImage; 13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // can't rasterize glyph 13428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 13466c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 13478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = aa; 13488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, *bounds); 13498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, 1352f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1353f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1354f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1355f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!state.fClip->isRect()); 13588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 13698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 13708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 13718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1377a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 13788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 13796c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 13808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 13818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 13828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 13838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 13848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 13858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_Bounder(const SkDraw1Glyph& state, 1389f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1390f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1391f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1392f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 14018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 14028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 14048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 14058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 14068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 14088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1412d055c1fde2128514167b315f4d104b177e04a3dereed@android.com 1413d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // we need to pass the origin, which we approximate with our 1414d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // (unadjusted) left,top coordinates (the caller called fixedfloor) 1415d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (state.fBounder->doIRectGlyph(cr, 1416d055c1fde2128514167b315f4d104b177e04a3dereed@android.com left - glyph.fLeft, 1417d055c1fde2128514167b315f4d104b177e04a3dereed@android.com top - glyph.fTop, glyph)) { 14188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 14196c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 14208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 14218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 14228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 14238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1429fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool hasCustomD1GProc(const SkDraw& draw) { 1430fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return draw.fProcs && draw.fProcs->fD1GProc; 1431fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1432fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 1433fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool needsRasterTextBlit(const SkDraw& draw) { 1434fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return !hasCustomD1GProc(draw); 1435fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1436fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 14378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, 14388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache) { 14398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDraw = draw; 14408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBounder = draw->fBounder; 14418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = draw->fClip; 14428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClipBounds = fClip->getBounds(); 14438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = blitter; 14448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCache = cache; 14458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14461d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*draw)) { 14478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw->fProcs->fD1GProc; 14488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == fBounder) { 14518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isRect()) { 14528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RectClip; 14538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RgnClip; 14558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_Bounder; 14588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 14628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText(const char text[], size_t byteLength, 14648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, const SkPaint& paint) const { 14658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 14668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1467f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 14688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 14708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 14718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 14728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 14738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 14778d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 14788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawText_asPaths(text, byteLength, x, y, paint); 14798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 14838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1484f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 14851d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1486f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1487f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1488f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1489f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1490f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1491f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1492f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1493f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 14948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1495a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 14968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform our starting point 14978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 14988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint loc; 1499f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix->mapXY(x, y, &loc); 15008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x = loc.fX; 15018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y = loc.fY; 15028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 15058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 15068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector stop; 15078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com measure_text(cache, glyphCacheProc, text, byteLength, &stop); 15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopX = stop.fX; 15118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopY = stop.fY; 15128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 15148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopX = SkScalarHalf(stopX); 15158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopY = SkScalarHalf(stopY); 15168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x -= stopX; 15188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y -= stopY; 15198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1520a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(x); 15228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(y); 15238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 15248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1525f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1526f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 15278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 1528cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*matrix); 1529cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == baseline) { 1530f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1531cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == baseline) { 1532f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 15338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1535f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // apply the bias here, so we don't have to add 1/2 in the loop 1536f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx += SK_FixedHalf; 1537f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fy += SK_FixedHalf; 15388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15391d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 15401d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 15411d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 15421d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 15431d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 15448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 154552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkDraw1Glyph d1g; 154652c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 15478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1549f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 15508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += autokern.adjust(glyph); 15528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 155452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com proc(d1g, fx, fy, glyph); 15558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += glyph.fAdvanceX; 15578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy += glyph.fAdvanceY; 15588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// last parameter is interpreted as SkFixed [x, y] 15628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// return the fixed position, which may be rounded or not by the caller 15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// e.g. subpixel doesn't round 15648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); 15658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); 15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), 15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); 15758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, 15808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - glyph.fAdvanceY); 15818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic AlignProc pick_align_proc(SkPaint::Align align) { 15848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const AlignProc gProcs[] = { 15858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com leftAlignProc, centerAlignProc, rightAlignProc 15868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1587a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); 15898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return gProcs[align]; 15918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass TextMapState { 15948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 15958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPoint fLoc; 1596a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState(const SkMatrix& matrix, SkScalar y) 15988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} 15998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); 1601a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc pickProc(int scalarsPerPosition); 1603a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 16058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& fMatrix; 16068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc fProc; 16078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fY; // ignored by MapXYProc 16088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // these are only used by Only... procs 16098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fScaleX, fTransX, fTransformedY; 16108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXProc(const TextMapState& state, const SkScalar pos[]) { 16128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc); 16138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1614a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXYProc(const TextMapState& state, const SkScalar pos[]) { 16168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc); 16178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1618a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyScaleXProc(const TextMapState& state, 16208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX, 16228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fTransformedY); 16238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1624a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyTransXProc(const TextMapState& state, 16268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(*pos + state.fTransX, state.fTransformedY); 16288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 16308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comTextMapState::Proc TextMapState::pickProc(int scalarsPerPosition) { 16328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1633a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (1 == scalarsPerPosition) { 16358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned mtype = fMatrix.getType(); 16368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 16378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXProc; 16388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 16398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fScaleX = fMatrix.getScaleX(); 16408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransX = fMatrix.getTranslateX(); 16418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) + 16428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix.getTranslateY(); 16438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (mtype & SkMatrix::kScale_Mask) ? 16448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MapOnlyScaleXProc : MapOnlyTransXProc; 16458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 16478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXYProc; 16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 16528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPosText(const char text[], size_t byteLength, 16548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[], SkScalar constY, 16558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scalarsPerPosition, const SkPaint& paint) const { 16568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 16578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 16588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1659f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 16608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 16628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 16638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 16648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 16658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 16668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 16698d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 16708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // TODO !!!! 16718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// this->drawText_asPaths(text, byteLength, x, y, paint); 16728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 16738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1675f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 16761d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1677f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1678f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1679f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1680f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1681f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1682f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1683a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1685f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 16868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1687a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16881d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 16891d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 16901d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 16911d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 16921d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 16938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 16948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com AlignProc alignProc = pick_align_proc(paint.getTextAlign()); 16958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph d1g; 16968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 1697f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com TextMapState tms(*matrix, constY); 16988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); 16998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 17018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // maybe we should skip the rounding if linearText is set 1702cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment roundBaseline = SkComputeAxisAlignmentForHText(*matrix); 17038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkPaint::kLeft_Align == paint.getTextAlign()) { 17058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1706a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1708a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(tms.fLoc.fX); 17108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(tms.fLoc.fY); 1711f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1712f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1714cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1715f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1716cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1717f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1719a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1720f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 1721f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx & fxMask, fy & fyMask); 1722a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 1724f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, glyph); 17258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph* glyph = &glyphCacheProc(cache, &text, 0, 0); 1731a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph->fWidth) { 17338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvX = glyph->fAdvanceX;) 17348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvY = glyph->fAdvanceY;) 17358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx, fy; 1737f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1738f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1740a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 17428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 17438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, *glyph, &fixedLoc); 17448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx = fixedLoc.fX; 17458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy = fixedLoc.fY; 17468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1747cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1748f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1749cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1750f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1753a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // have to call again, now that we've been "aligned" 1755f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com glyph = &glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 17568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the assumption is that the advance hasn't changed 17578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvX == glyph->fAdvanceX); 17588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvY == glyph->fAdvanceY); 1759a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1760f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, *glyph); 17618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // not subpixel 17668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the last 2 parameters are ignored 17688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1769a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 17718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1772a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 17748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, glyph, &fixedLoc); 1775a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1776f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fixedLoc.fX + SK_FixedHalf, 1777f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fixedLoc.fY + SK_FixedHalf, glyph); 17788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 17838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined _WIN32 && _MSC_VER >= 1300 17858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( pop ) 17868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 17878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 17898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathMeasure.h" 17918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpoints(SkPoint dst[], const SkPoint src[], int count, 17938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure& meas, const SkMatrix& matrix) { 17948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc proc = matrix.getMapXYProc(); 17958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 17978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pos; 17988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector tangent; 17998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(matrix, src[i].fX, src[i].fY, &pos); 18018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = pos.fX; 18028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = pos.fY; 18038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com meas.getPosTan(sx, &pos, &tangent); 18058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* This is the old way (that explains our approach but is way too slow 18078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 18088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pt; 18098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pt.set(sx, sy); 18118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setSinCos(tangent.fY, tangent.fX); 18128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.preTranslate(-sx, 0); 18138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(pos.fX, pos.fY); 18148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapPoints(&dst[i], &pt, 1); 18158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 18168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy), 18178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos.fY + SkScalarMul(tangent.fX, sy)); 18188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* TODO 18228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Need differentially more subdivisions when the follow-path is curvy. Not sure how to 18248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com determine that, but we need it. I guess a cheap answer is let the caller tell us, 18258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out. 18268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 18278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, 18288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix) { 18298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Iter iter(src, false); 18308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint srcP[4], dstP[3]; 18318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Verb verb; 18328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { 18348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (verb) { 18358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kMove_Verb: 18368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 1, meas, matrix); 18378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->moveTo(dstP[0]); 18388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kLine_Verb: 18408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // turn lines into quads to look bendy 18418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX); 18428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY); 18438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 2, meas, matrix); 18448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 18458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kQuad_Verb: 18478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 2, meas, matrix); 18488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 18498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kCubic_Verb: 18518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 3, meas, matrix); 18528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->cubicTo(dstP[0], dstP[1], dstP[2]); 18538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kClose_Verb: 18558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->close(); 18568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 18588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"unknown verb"); 18598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawTextOnPath(const char text[], size_t byteLength, 18658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& follow, const SkMatrix* matrix, 18668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 18678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 18688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 18708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 18718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 18728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 18738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 18748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 18778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure meas(follow, false); 18788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar hOffset = 0; 18798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 18818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 18828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar pathLen = meas.getLength(); 18838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 18848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathLen = SkScalarHalf(pathLen); 18858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hOffset += pathLen; 18878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 18908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos; 18918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix scaledMatrix; 18928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar scale = iter.getPathScale(); 18938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scaledMatrix.setScale(scale, scale); 1895a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 18978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 18988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m(scaledMatrix); 18998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postTranslate(xpos + hOffset, 0); 19018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (matrix) { 19028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postConcat(*matrix); 19038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpath(&tmp, *iterPath, meas, m); 1905f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1906f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); 1907f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1908f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(tmp, iter.getPaint(), NULL, true); 1909f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 19108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1913cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#ifdef ANDROID 1914cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.comvoid SkDraw::drawPosTextOnPath(const char text[], size_t byteLength, 1915cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPoint pos[], const SkPaint& paint, 1916cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath& path, const SkMatrix* matrix) const { 1917cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // nothing to draw 1918cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty() || 1919cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 1920cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return; 1921cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1922cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1923cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix scaledMatrix; 1924cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPathMeasure meas(path, false); 1925cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1926cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc( 1927cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint::kForward_TextBufferDirection, true); 1928cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1929cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Copied (modified) from SkTextToPathIter constructor to setup paint 1930cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint tempPaint(paint); 1931cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1932cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setLinearText(true); 1933cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup 1934cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1935cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (tempPaint.getPathEffect() == NULL && !(tempPaint.getStrokeWidth() > 0 1936cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com && tempPaint.getStyle() != SkPaint::kFill_Style)) { 1937cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setStyle(SkPaint::kFill_Style); 1938cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setPathEffect(NULL); 1939cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1940cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // End copied from SkTextToPathIter constructor 1941cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1942cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // detach cache 1943cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache* cache = tempPaint.detachCache(NULL); 1944cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1945cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Must set scale, even if 1 1946cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkScalar scale = SK_Scalar1; 1947cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com scaledMatrix.setScale(scale, scale); 1948cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1949cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Loop over all glyph ids 1950cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for (const char* stop = text + byteLength; text < stop; pos++) { 1951cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1952cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkGlyph& glyph = glyphCacheProc(cache, &text); 1953cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPath tmp; 1954cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1955cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath* glyphPath = cache->findPath(glyph); 1956cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (glyphPath == NULL) { 1957cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com continue; 1958cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1959cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1960cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix m(scaledMatrix); 1961cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postTranslate(pos->fX, 0); 1962cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1963cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (matrix) { 1964cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postConcat(*matrix); 1965cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1966cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1967cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com morphpath(&tmp, *glyphPath, meas, m); 1968cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com this->drawPath(tmp, tempPaint); 1969cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1970cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1971cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1972cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // re-attach cache 1973cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache::AttachCache(cache); 1974cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com} 1975cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif 1976cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 19778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 19788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct VertState { 19808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int f0, f1, f2; 19818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState(int vCount, const uint16_t indices[], int indexCount) 19838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fIndices(indices) { 19848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCurrIndex = 0; 19858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (indices) { 19868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = indexCount; 19878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 19888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = vCount; 19898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1991a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1992a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com typedef bool (*Proc)(VertState*); 19938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkCanvas::VertexMode mode); 19948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 19968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCount; 19978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCurrIndex; 19988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* fIndices; 1999a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 20008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool Triangles(VertState*); 20018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TrianglesX(VertState*); 20028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStrip(VertState*); 20038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStripX(VertState*); 20048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFan(VertState*); 20058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFanX(VertState*); 20068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 20078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::Triangles(VertState* state) { 20098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TrianglesX(VertState* state) { 20218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStrip(VertState* state) { 20348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 20408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 1; 20418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 0; 20428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStripX(VertState* state) { 20518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 20588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 1]; 20598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 0]; 20608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFan(VertState* state) { 20698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = 0; 20748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFanX(VertState* state) { 20818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[0]; 20878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comVertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { 20948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 20958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangles_VertexMode: 20968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TrianglesX : Triangles; 20978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleStrip_VertexMode: 20988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleStripX : TriangleStrip; 20998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleFan_VertexMode: 21008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleFanX : TriangleFan; 21018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 21028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 21038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRegion*, 21078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 21088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic HairProc ChooseHairProc(bool doAntiAlias) { 21108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; 21118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool texture_to_matrix(const VertState& state, const SkPoint verts[], 21148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint texs[], SkMatrix* matrix) { 21158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src[3], dst[3]; 2116a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[0] = texs[state.f0]; 21188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[1] = texs[state.f1]; 21198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[2] = texs[state.f2]; 21208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[0] = verts[state.f0]; 21218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[1] = verts[state.f1]; 21228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[2] = verts[state.f2]; 21238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return matrix->setPolyToPoly(src, dst, 3); 21248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkTriColorShader : public SkShader { 21278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 21288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader() {} 21298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); 2131a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count); 2133a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 21358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader(SkFlattenableReadBuffer& buffer) : SkShader(buffer) {} 2136a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 2138a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 21408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix fDstToUnit; 21418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor fColors[3]; 2142a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 21448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkTriColorShader, (buffer)); 21458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkShader INHERITED; 21478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 21488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkTriColorShader::setup(const SkPoint pts[], const SkColor colors[], 21508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index0, int index1, int index2) { 2151a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[0] = SkPreMultiplyColor(colors[index0]); 21538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[1] = SkPreMultiplyColor(colors[index1]); 21548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[2] = SkPreMultiplyColor(colors[index2]); 2155a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m, im; 21578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 21588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(0, pts[index1].fX - pts[index0].fX); 21598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(1, pts[index2].fX - pts[index0].fX); 21608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(2, pts[index0].fX); 21618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(3, pts[index1].fY - pts[index0].fY); 21628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(4, pts[index2].fY - pts[index0].fY); 21638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(5, pts[index0].fY); 21648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!m.invert(&im)) { 21658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fDstToUnit.setConcat(im, this->getTotalInverse()); 21688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 2171689411a87ca7d19abe04b5c9baff26bd96b2123ereed@android.com#include "SkComposeShader.h" 21728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic int ScalarTo256(SkScalar v) { 21748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale = SkScalarToFixed(v) >> 8; 21758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale < 0) { 21768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 0; 21778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale > 255) { 21798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 255; 21808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkAlpha255To256(scale); 21828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkTriColorShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { 21858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src; 2186a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 21888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 21898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += 1; 2190a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale1 = ScalarTo256(src.fX); 21928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale2 = ScalarTo256(src.fY); 21938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale0 = 256 - scale1 - scale2; 21948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale0 < 0) { 21958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale1 > scale2) { 21968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale2 = 256 - scale1; 21978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale1 = 256 - scale2; 21998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale0 = 0; 22018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2202a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 22048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[1], scale1) + 22058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[2], scale2); 22068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, 22108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint textures[], 22118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 22128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 22138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 22148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == count || NULL != vertices); 2215a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // abort early if there is nothing to draw 22178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count < 3 || (indices && indexCount < 3) || fClip->isEmpty() || 22188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 22198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2221a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform out vertices into device coordinates 22238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoSTMalloc<16, SkPoint> storage(count); 22248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint* devVerts = storage.get(); 22258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapPoints(devVerts, vertices, count); 2226a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder) { 22288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 22298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(devVerts, count); 22308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!fBounder->doRect(bounds, paint)) { 22318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2234a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 22368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com We can draw the vertices in 1 of 4 ways: 22378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - solid color (no shader/texture[], no colors[]) 22398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just colors (no shader/texture[], has colors[]) 22408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just texture (has shader/texture[], no colors[]) 22418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - colors * texture (has shader/texture[], has colors[]) 2242a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Thus for texture drawing, we need both texture[] and a shader. 22448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 22458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader triShader; // must be above declaration of p 22478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 22488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* shader = p.getShader(); 22508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == shader) { 22518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we have no shader, we ignore the texture coordinates 22528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textures = NULL; 22538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (NULL == textures) { 22548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we don't have texture coordinates, ignore the shader 22558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(NULL); 22568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader = NULL; 22578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup the custom shader (if needed) 22608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 22618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == textures) { 22628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // just colors (no texture) 22638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(&triShader); 22648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 22658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // colors * texture 22668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(shader); 22678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool releaseMode = false; 22688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == xmode) { 2269845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com xmode = SkXfermode::Create(SkXfermode::kMultiply_Mode); 22708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com releaseMode = true; 22718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* compose = SkNEW_ARGS(SkComposeShader, 22738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (&triShader, shader, xmode)); 22748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(compose)->unref(); 22758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (releaseMode) { 22768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xmode->unref(); 22778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); 22828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup our state and function pointer for iterating triangles 22838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState state(count, indices, indexCount); 22848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState::Proc vertProc = state.chooseProc(vmode); 2285a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures || NULL != colors) { 22878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix localM, tempM; 22888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasLocalM = shader && shader->getLocalMatrix(&localM); 2289a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 22918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setContext(*fBitmap, p, *fMatrix)) { 22928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colors = NULL; 22938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2295a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 22978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures) { 22988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (texture_to_matrix(state, vertices, textures, &tempM)) { 22998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tempM.postConcat(localM); 23018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(tempM); 23038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to recal setContext since we changed the local matrix 23048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!shader->setContext(*fBitmap, p, *fMatrix)) { 23058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setup(vertices, colors, 23118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.f0, state.f1, state.f2)) { 23128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillTriangle(devVerts[state.f0], devVerts[state.f1], 23168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devVerts[state.f2], fClip, blitter.get()); 23178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now restore the shader's original local matrix 23198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != shader) { 23208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(localM); 23228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->resetLocalMatrix(); 23248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // no colors[] and no texture 23288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); 23298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 23308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f0], devVerts[state.f1], fClip, blitter.get()); 23318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f1], devVerts[state.f2], fClip, blitter.get()); 23328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f2], devVerts[state.f0], fClip, blitter.get()); 23338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23370a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23380a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 23418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2342f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkDraw::validate() const { 23438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fBitmap != NULL); 23448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fMatrix != NULL); 23458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fClip != NULL); 23468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = fClip->getBounds(); 23488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect br; 23498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2350f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com br.set(0, 0, fBitmap->width(), fBitmap->height()); 23518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(cr.isEmpty() || br.contains(cr)); 2352f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 2353f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // assert that both are null, or both are not-null 2354f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkASSERT(!fMVMatrix == !fExtMatrix); 23558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 23588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23590a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23600a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com 23610a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.comSkBounder::SkBounder() { 23620a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com // initialize up front. This gets reset by SkCanvas before each draw call. 23630a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com fClip = &SkRegion::GetEmptyRegion(); 23640a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com} 23658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doIRect(const SkIRect& r) { 23678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect rr; 23688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return rr.intersect(fClip->getBounds(), r) && this->onIRect(rr); 23698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2371d055c1fde2128514167b315f4d104b177e04a3dereed@android.com// TODO: change the prototype to take fixed, and update the callers 2372d055c1fde2128514167b315f4d104b177e04a3dereed@android.combool SkBounder::doIRectGlyph(const SkIRect& r, int x, int y, 2373d055c1fde2128514167b315f4d104b177e04a3dereed@android.com const SkGlyph& glyph) { 2374474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com SkIRect rr; 2375d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (!rr.intersect(fClip->getBounds(), r)) { 2376d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return false; 2377d055c1fde2128514167b315f4d104b177e04a3dereed@android.com } 2378d055c1fde2128514167b315f4d104b177e04a3dereed@android.com GlyphRec rec; 2379d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.set(SkIntToFixed(x), SkIntToFixed(y)); 2380d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fRSB.set(rec.fLSB.fX + glyph.fAdvanceX, 2381d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.fY + glyph.fAdvanceY); 2382d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fGlyphID = glyph.getGlyphID(); 2383d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fFlags = 0; 2384d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return this->onIRectGlyph(rr, rec); 2385474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com} 2386474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com 23878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doHairline(const SkPoint& pt0, const SkPoint& pt1, 23888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 23898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 23908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar v0, v1; 23918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fX; 23938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fX; 23948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 23958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 23968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = SkScalarFloor(v0); 23988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = SkScalarCeil(v1); 23998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fY; 24018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fY; 24028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 24038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 24048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = SkScalarFloor(v0); 24068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = SkScalarCeil(v1); 24078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doRect(const SkRect& rect, const SkPaint& paint) { 24158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getStyle() == SkPaint::kFill_Style) { 24188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.round(&r); 24198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 24208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rad = -1; 24218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.roundOut(&r); 24228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rad = -2; 24248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(rad, rad); 24268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doPath(const SkPath& path, const SkPaint& paint, bool doFill) { 2431d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkIRect r; 2432d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& bounds = path.getBounds(); 24338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 24358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.round(&r); 24368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 24378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&r); 24388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkBounder::commit() { 24478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override in subclass 24488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////////////////////// 24518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 24538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 24548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 24558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 24568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, 24588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 24598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds) { 24608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (devPath.isEmpty()) { 24618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 24628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // init our bounds from the path 24658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2466d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkRect pathBounds = devPath.getBounds(); 24678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); 24688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.roundOut(bounds); 24698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2470a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24715af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIPoint margin; 24728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (filter) { 24738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(filterMatrix); 2474a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24755af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkMask srcM, dstM; 2476a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fBounds = *bounds; 24788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fFormat = SkMask::kA8_Format; 24798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fImage = NULL; 24808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { 24818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 24828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2484a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24855af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com // (possibly) trim the bounds to reflect the clip 24868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (plus whatever slop the filter needs) 24875af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (clipBounds) { 24885af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIRect tmp = *clipBounds; 24893555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // Ugh. Guard against gigantic margins from wacky filters. Without this 24903555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // check we can request arbitrary amounts of slop beyond our visible 24913555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // clip, and bring down the renderer (at least on finite RAM machines 24923555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // like handsets, etc.). Need to balance this invented value between 24933555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // quality of large filters like blurs, and the corresponding memory 24943555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // requests. 24953555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com static const int MAX_MARGIN = 128; 24963555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), 24973555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com -SkMin32(margin.fY, MAX_MARGIN)); 24985af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (!bounds->intersect(tmp)) { 24995af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com return false; 25005af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com } 25018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 25048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void draw_into_mask(const SkMask& mask, const SkPath& devPath) { 25078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap bm; 25088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw; 25098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion clipRgn; 25108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 25118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint paint; 25128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height(), mask.fRowBytes); 25148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setPixels(mask.fImage); 25158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRgn.setRect(0, 0, mask.fBounds.width(), mask.fBounds.height()); 25178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), 25188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 25198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBitmap = &bm; 25218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fClip = &clipRgn; 25228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 25238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBounder = NULL; 25248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.setAntiAlias(true); 25258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawPath(devPath, paint); 25268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 25298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 25308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask* mask, SkMask::CreateMode mode) { 25318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustRenderImage_CreateMode != mode) { 25328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds)) 25338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2535a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { 25378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fFormat = SkMask::kA8_Format; 25388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fRowBytes = mask->fBounds.width(); 2539543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask->computeImageSize(); 2540543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 2541543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // we're too big to allocate the mask, abort 2542543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return false; 2543543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 2544543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com mask->fImage = SkMask::AllocImage(size); 25458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask->fImage, 0, mask->computeImageSize()); 25468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustComputeBounds_CreateMode != mode) { 25498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_into_mask(*mask, devPath); 25508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2551a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 25538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2554