SkDraw.cpp revision dcd0f3a980095b77ebe605b49777a4bd37ca7b0a
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 530dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (fClip->isEmpty()) { 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 534fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (fBounder) { 535fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (!bounder_points(fBounder, mode, count, pts, paint, *fMatrix)) { 536fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 537fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 538fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 539fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // clear the bounder and call this again, so we don't invoke the bounder 540fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // later if we happen to call ourselves for drawRect, drawPath, etc. 541fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com SkDraw noBounder(*this); 542fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.fBounder = NULL; 543fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.drawPoints(mode, count, pts, paint, forceUseDevice); 544fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 545fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 546fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 5478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec rec; 548f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (!forceUseDevice && rec.init(mode, paint, fMatrix, fClip)) { 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint devPts[MAX_DEV_PTS]; 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* bltr = blitter.get(); 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec::Proc proc = rec.chooseProc(bltr); 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we have to back up subsequent passes if we're in polygon mode 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t backup = (SkCanvas::kPolygon_PointMode == mode); 557a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t n = count; 5608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (n > MAX_DEV_PTS) { 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com n = MAX_DEV_PTS; 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix->mapPoints(devPts, pts, n); 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(rec, devPts, n, bltr); 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pts += n - backup; 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(count >= n); 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= n; 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count > 0) { 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count += backup; 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (count != 0); 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPoints_PointMode: { 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // temporarily mark the paint as filling. 57640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint newPaint(paint); 57740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com newPaint.setStyle(SkPaint::kFill_Style); 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 57940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkScalar width = newPaint.getStrokeWidth(); 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar radius = SkScalarHalf(width); 581a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 58240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix preMatrix; 585a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.addCircle(0, 0, radius); 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preMatrix.setTranslate(pts[i].fX, pts[i].fY); 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // pass true for the last point, since we can modify 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // then path then 591f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 59240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawPath(*this, path, newPaint, &preMatrix, 593f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com (count-1) == i); 594f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 59540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawPath(path, newPaint, &preMatrix, 59640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (count-1) == i); 597f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 601a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = pts[i].fX - radius; 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = pts[i].fY - radius; 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = r.fLeft + width; 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = r.fTop + width; 607f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 60840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawRect(*this, r, newPaint); 609f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 61040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawRect(r, newPaint); 611f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kLines_PointMode: 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPolygon_PointMode: { 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= 1; 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStyle(SkPaint::kStroke_Style); 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i += inc) { 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.moveTo(pts[i]); 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.lineTo(pts[i+1]); 626f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 627f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, path, p, NULL, true); 628f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 629f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(path, p, NULL, true); 630f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.rewind(); 6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_lefttop(SkRect* r) { 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkPoint*)(void*)r; 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_rightbottom(SkRect* r) { 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return ((SkPoint*)(void*)r) + 1; 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 647761fb62b0eb174783316d2a8b933fba896ca6355reed@google.comstatic bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, 648761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint* strokeSize) { 649761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com if (SkPaint::kMiter_Join != paint.getStrokeJoin() || 650761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com paint.getStrokeMiter() < SK_ScalarSqrt2) { 651761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return false; 652761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com } 65362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 654761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkASSERT(matrix.rectStaysRect()); 655761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() }; 656761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com matrix.mapVectors(strokeSize, &pt, 1); 6576115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fX = SkScalarAbs(strokeSize->fX); 6586115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fY = SkScalarAbs(strokeSize->fY); 659761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return true; 6607ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org} 6617ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 66262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comSkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, 66362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const SkMatrix& matrix, 66462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint* strokeSize) { 6657ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org RectType rtype; 6667ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org const SkScalar width = paint.getStrokeWidth(); 66762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const bool zeroWidth = (0 == width); 6687ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::Style style = paint.getStyle(); 66962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6707ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) { 6717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org style = SkPaint::kFill_Style; 6727ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 67362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect() || paint.getMaskFilter() || 67562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com paint.getRasterizer() || !matrix.rectStaysRect() || 6767ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::kStrokeAndFill_Style == style) { 67762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 67862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (SkPaint::kFill_Style == style) { 6797ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kFill_RectType; 6807ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else if (zeroWidth) { 6817ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kHair_RectType; 68262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (easy_rect_join(paint, matrix, strokeSize)) { 6837ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kStroke_RectType; 6847ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 6857ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kPath_RectType; 6867ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 68762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return rtype; 68862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com} 68962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 69040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comstatic SkPoint* rect_points(SkRect& r, int index) { 69140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT((unsigned)index < 2); 69240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com return &((SkPoint*)(void*)&r)[index]; 69340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com} 69440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com 69562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comvoid SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const { 69662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkDEBUGCODE(this->validate();) 6977ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 69862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com // nothing to draw 699dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (fClip->isEmpty()) { 70062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return; 70162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 70262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 70362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint strokeSize; 70462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); 70562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 70662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#ifdef SK_DISABLE_FAST_AA_STROKE_RECT 70762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (kStroke_RectType == rtype && paint.isAntiAlias()) { 70862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 70962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 71062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#endif 71162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 7127ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (kPath_RectType == rtype) { 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.addRect(rect); 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.setFillType(SkPath::kWinding_FillType); 716187d5595901d1120d9425851e5afdd773f574502reed@android.com this->drawPath(tmp, paint, NULL, true); 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix = *fMatrix; 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect devRect; 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform rect into devRect 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fLeft, rect.fTop, rect_points(devRect, 0)); 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fRight, rect.fBottom, rect_points(devRect, 1)); 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.sort(); 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doRect(devRect, paint)) { 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // look for the quick exit, before we build a blitter 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.roundOut(&ir); 73855e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com if (paint.getStyle() != SkPaint::kFill_Style) { 73955e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com // extra space for hairlines 74055e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com ir.inset(-1, -1); 74155e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com } 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(ir)) 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitterStorage(*fBitmap, matrix, paint); 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = blitterStorage.get(); 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* clip = fClip; 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 750b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter 751b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // case we are also hairline (if we've gotten to here), which devolves to 752b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // effectively just kFill 7537ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org switch (rtype) { 7547ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kFill_RectType: 7557ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7567ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiFillRect(devRect, clip, blitter); 7577ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7587ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::FillRect(devRect, clip, blitter); 7597ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7607ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7617ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kStroke_RectType: 7627ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 763761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::AntiFrameRect(devRect, strokeSize, clip, blitter); 7647ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 765761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::FrameRect(devRect, strokeSize, clip, blitter); 7667ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7677ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7687ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kHair_RectType: 7697ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7707ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiHairRect(devRect, clip, blitter); 7717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7727ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::HairRect(devRect, clip, blitter); 7737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7747ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7757ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org default: 7767ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkASSERT(!"bad rtype"); 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (srcM.fBounds.isEmpty()) { 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7850a60b3d32eae945688b69599f11679662657f751bungeman@google.com const SkMask* mask = &srcM; 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7870a60b3d32eae945688b69599f11679662657f751bungeman@google.com SkMask dstM; 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getMaskFilter() && 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask = &dstM; 791bf2ac7e52f84095368dc50600fd6e78cc96044e3bungeman@google.com } else { 792bf2ac7e52f84095368dc50600fd6e78cc96044e3bungeman@google.com dstM.fImage = NULL; 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7940a60b3d32eae945688b69599f11679662657f751bungeman@google.com SkAutoMaskImage ami(&dstM, false); 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(mask->fBounds)) { 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitMaskRegion(*mask, *fClip); 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 805ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.comstatic SkScalar fast_len(const SkVector& vec) { 806ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar x = SkScalarAbs(vec.fX); 807ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar y = SkScalarAbs(vec.fY); 808ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com if (x < y) { 809ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkTSwap(x, y); 810ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 811ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return x + SkScalarHalf(y); 812ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 813ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 814ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.comstatic bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) { 815ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkXfermode::Coeff dc; 816ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!SkXfermode::AsCoeff(xfer, NULL, &dc)) { 817ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 818ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 819ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 820ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com switch (dc) { 821ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kOne_Coeff: 822ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISA_Coeff: 823ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISC_Coeff: 824ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 825ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com default: 826ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 827ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 828ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com} 829ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 830ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.combool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, 831ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha* newAlpha) { 832ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkASSERT(newAlpha); 833ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkPaint::kStroke_Style != paint.getStyle()) { 834ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 835ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 836ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar strokeWidth = paint.getStrokeWidth(); 837ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (0 == strokeWidth) { 838ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = paint.getAlpha(); 839ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 840ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 841ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 842ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // if we get here, we need to try to fake a thick-stroke with a modulated 843ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // hairline 844ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 845ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!paint.isAntiAlias()) { 846ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 847ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 848ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!xfermodeSupportsCoverageAsAlpha(paint.getXfermode())) { 849ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 850ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 8518d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com if (matrix.hasPerspective()) { 852ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 853ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 854ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 855ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkVector src[2], dst[2]; 856ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[0].set(strokeWidth, 0); 857ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[1].set(0, strokeWidth); 858ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com matrix.mapVectors(dst, src, 2); 859ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len0 = fast_len(dst[0]); 860ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len1 = fast_len(dst[1]); 861652807bbc8c57e5fa9622126b51fd369f5c67935agl@chromium.org if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { 862ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar modulate = SkScalarAve(len0, len1); 8636a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#if 0 864ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = SkToU8(SkScalarRoundToInt(modulate * paint.getAlpha())); 8656a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#else 8666a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // this is the old technique, which we preserve for now so we don't 8676a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // change previous results (testing) 8686a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // the new way seems fine, its just (a tiny bit) different 8696a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com int scale = (int)SkScalarMul(modulate, 256); 8706a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com *newAlpha = paint.getAlpha() * scale >> 8; 8716a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#endif 872ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return true; 873ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 874ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 875ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 876ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 87732e5d97ccf60f859db063ebd6e903c362e625767reed@google.comvoid SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* prePathMatrix, bool pathIsMutable) const { 879f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 882dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (fClip->isEmpty()) { 8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* pathPtr = (SkPath*)&origSrcPath; 8878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool doFill = true; 8888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmpPath; 8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix tmpMatrix; 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 8918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (prePathMatrix) { 89332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style || 89432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getRasterizer()) { 8958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* result = pathPtr; 896a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 8978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!pathIsMutable) { 8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result = &tmpPath; 8998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathIsMutable = true; 9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*prePathMatrix, result); 9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = result; 9038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!tmpMatrix.setConcat(*matrix, *prePathMatrix)) { 9058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overflow 9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix = &tmpMatrix; 9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // at this point we're done with prePathMatrix 9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) 913a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 91432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com const SkPaint* paint = &origPaint; 91532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkTLazy<SkPaint> lazyPaint; 916a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 917ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com { 918ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha newAlpha; 919ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkDrawTreatAsHairline(origPaint, *matrix, &newAlpha)) { 92032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.set(origPaint); 921ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com lazyPaint.get()->setAlpha(newAlpha); 92232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.get()->setStrokeWidth(0); 92332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint = lazyPaint.get(); 9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 926a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 92732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { 92832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com doFill = paint->getFillPath(*pathPtr, &tmpPath); 9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = &tmpPath; 9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 931a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 93232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()) { 9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 93432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, 93532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com &fClip->getBounds(), paint->getMaskFilter(), &mask, 9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::kComputeBoundsAndRenderImage_CreateMode)) { 93732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com this->drawDevMask(mask, *paint); 9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::FreeImage(mask.fImage); 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // avoid possibly allocating a new path in transform if we can 9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; 9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform the path into device space 9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*matrix, devPathPtr); 9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 94932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint); 9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // how does filterPath() know to fill or hairline the path??? <mrr> 95232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getMaskFilter() && 95332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fClip, 95432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com fBounder, blitter.get())) { 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // filterPath() called the blitter, so we're done 9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 95832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (fBounder && !fBounder->doPath(*devPathPtr, *paint, doFill)) { 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 96332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiFillPath(*devPathPtr, *fClip, blitter.get()); 9658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillPath(*devPathPtr, *fClip, blitter.get()); 9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 96932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairPath(*devPathPtr, fClip, blitter.get()); 9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairPath(*devPathPtr, fClip, blitter.get()); 9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9770baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com/** For the purposes of drawing bitmaps, if a matrix is "almost" translate 9780baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com go ahead and treat it as if it were, so that subsequent code can go fast. 9790baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com */ 9800baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.comstatic bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { 9810baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkMatrix::TypeMask mask = matrix.getType(); 9820baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com 9830baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 9840baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return false; 9850baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9860baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & SkMatrix::kScale_Mask) { 9870baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sx = matrix[SkMatrix::kMScaleX]; 9880baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sy = matrix[SkMatrix::kMScaleY]; 9890baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int w = bitmap.width(); 9900baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int h = bitmap.height(); 9910baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w))); 9920baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h))); 9930baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return sw == w && sh == h; 9940baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9950baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com // if we got here, we're either kTranslate_Mask or identity 9960baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return true; 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap.getConfig() == SkBitmap::kA8_Config); 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1003a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com if (just_translate(*fMatrix, bitmap)) { 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(fMatrix->getTranslateX()); 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(fMatrix->getTranslateY()); 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = bitmap.rowBytes(); 10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = bitmap.getAddr8(0, 0); 1012a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // need to xform the bitmap first 10158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 1017a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, 10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); 10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapRect(&r); 10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.round(&mask.fBounds); 1022a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // set the mask's bounds to the transformed bitmap-bounds, 10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // clipped to the actual device 10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devBounds; 10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); 10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need intersect(l, t, r, b) on irect 10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!mask.fBounds.intersect(devBounds)) { 10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1033543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com 10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = SkAlign4(mask.fBounds.width()); 1036543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask.computeImageSize(); 1037543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 1038543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // the mask is too big to allocated, draw nothing 1039543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return; 1040543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // allocate (and clear) our temp buffer to hold the transformed bitmap 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMalloc storage(size); 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)storage.get(); 10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask.fImage, 0, size); 1046a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now draw our bitmap(src) into mask(dst), transformed by the matrix 10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap device; 10508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), 10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.height(), mask.fRowBytes); 10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setPixels(mask.fImage); 1053a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas c(device); 10558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need the unclipped top/left for the translate 10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.translate(-SkIntToScalar(mask.fBounds.fLeft), 10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.concat(*fMatrix); 10593469c76c40790b409621fd7eff34f56240718549reed@android.com 10603469c76c40790b409621fd7eff34f56240718549reed@android.com // We can't call drawBitmap, or we'll infinitely recurse. Instead 1061fb12c3e6ba84f95dc15fbaddc239dede0ba1d60ereed@android.com // we manually build a shader and draw that into our new mask 10623469c76c40790b409621fd7eff34f56240718549reed@android.com SkPaint tmpPaint; 10633469c76c40790b409621fd7eff34f56240718549reed@android.com tmpPaint.setFlags(paint.getFlags()); 106440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, tmpPaint); 10653469c76c40790b409621fd7eff34f56240718549reed@android.com SkRect rr; 10663469c76c40790b409621fd7eff34f56240718549reed@android.com rr.set(0, 0, SkIntToScalar(bitmap.width()), 10673469c76c40790b409621fd7eff34f56240718549reed@android.com SkIntToScalar(bitmap.height())); 106840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com c.drawRect(rr, install.paintWithShader()); 10698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& m, const SkRegion& c, 10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& srcR) { 10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect dstR; 10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devIR; 1078a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.mapRect(&dstR, srcR); 1080a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com dstR.roundOut(&devIR); 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return c.quickReject(devIR); 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& matrix, const SkRegion& clip, 10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int width, int height) { 10868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); 10888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return clipped_out(matrix, clip, r); 10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 109240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1093f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 10948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 10968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 10978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 1098dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com bitmap.getConfig() == SkBitmap::kNo_Config) { 10998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1101a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1102a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#ifndef SK_ALLOW_OVER_32K_BITMAPS 11038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // run away on too-big bitmaps for now (exceed 16.16) 11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.width() > 32767 || bitmap.height() > 32767) { 11058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1107a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#endif 1108a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 110940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 111040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 1111a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 11138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!matrix.setConcat(*fMatrix, prematrix)) { 11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (clipped_out(matrix, *fClip, bitmap.width(), bitmap.height())) { 11188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1121218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (fBounder && just_translate(matrix, bitmap)) { 1122218521e15706c4377b1be49d931c4d7c8d597445reed@android.com SkIRect ir; 1123218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t ix = SkScalarRound(matrix.getTranslateX()); 1124218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t iy = SkScalarRound(matrix.getTranslateY()); 1125218521e15706c4377b1be49d931c4d7c8d597445reed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1126218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (!fBounder->doIRect(ir)) { 1127218521e15706c4377b1be49d931c4d7c8d597445reed@android.com return; 1128218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1129218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1130218521e15706c4377b1be49d931c4d7c8d597445reed@android.com 1131218521e15706c4377b1be49d931c4d7c8d597445reed@android.com // only lock the pixels if we passed the clip and bounder tests 11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoLockPixels alp(bitmap); 11338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // after the lock, check if we are valid 11348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!bitmap.readyToDraw()) { 11358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11380baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (bitmap.getConfig() != SkBitmap::kA8_Config && 11390baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com just_translate(matrix, bitmap)) { 11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(matrix.getTranslateX()); 11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(matrix.getTranslateY()); 11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ix, iy, storage, sizeof(storage)); 11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 11468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 11498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 11508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, ir); 11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if 0 11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("---- MISSING sprite case: config=%d [%d %d], device=%d, xfer=%p, alpha=0x%X colorFilter=%p\n", 11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.config(), bitmap.width(), bitmap.height(), fBitmap->config(), 11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getXfermode(), paint.getAlpha(), paint.getColorFilter()); 11648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 11658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1166a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now make a temp draw on the stack, and use it 11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // 11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 11708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 1171a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.getConfig() == SkBitmap::kA8_Config) { 11738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawBitmapAsMask(bitmap, paint); 11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 117540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(bitmap.width()), 11798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.height())); 1180a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this ok if paint has a rasterizer? 118140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, install.paintWithShader()); 11828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 118640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1187f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 1188a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 11908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 11918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 1192dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com bitmap.getConfig() == SkBitmap::kNo_Config) { 11938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect bounds; 11978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); 11988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(bounds)) { 12008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // nothing to draw 12018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 120340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 120440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 12058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == paint.getColorFilter()) { 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 12088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 12098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x, y, storage, sizeof(storage)); 12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(bounds)) { 12158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, bounds); 12198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 12208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 12228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 12238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 12248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 122940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 123040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& shaderPaint = install.paintWithShader(); 12318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 12348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // get a scalar version of our rect 12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(bounds); 12378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // tell the shader our offset 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(r.fLeft, r.fTop); 124040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com shaderPaint.getShader()->setLocalMatrix(matrix); 1241a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.reset(); 12448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // call ourself with a rect 1246a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this OK if paint has a rasterizer? 124740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, shaderPaint); 12488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 12518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalerContext.h" 12538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGlyphCache.h" 12548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, 12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char text[], size_t byteLength, SkVector* stopVector) { 12588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = 0, y = 0; 12598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 12608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 1262a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 12648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // don't need x, y here, since all subpixel variants will have the 12658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // same advance 12668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 12678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += autokern.adjust(glyph) + glyph.fAdvanceX; 12698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y += glyph.fAdvanceY; 12708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); 12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(text == stop); 12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText_asPaths(const char text[], size_t byteLength, 12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, 12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 1279f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 12828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setScale(iter.getPathScale(), iter.getPathScale()); 12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(x, y); 12868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos, prevXPos = 0; 12898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 12918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(xpos - prevXPos, 0); 1292f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPaint& pnt = iter.getPaint(); 1293f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1294f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, *iterPath, pnt, &matrix, false); 1295f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1296f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(*iterPath, pnt, &matrix, false); 1297f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 12988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com prevXPos = xpos; 12998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// disable warning : local variable used without having been initialized 1303a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#if defined _WIN32 && _MSC_VER >= 1300 13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( push ) 13058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( disable : 4701 ) 13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 13098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RectClip(const SkDraw1Glyph& state, 1311f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1312f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1313f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1314f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClip->isRect()); 13178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClipBounds == state.fClip->getBounds()); 13198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int right = left + glyph.fWidth; 13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int bottom = top + glyph.fHeight; 13258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect storage; 13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds = &mask.fBounds; 13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, right, bottom); 13318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // this extra test is worth it, assuming that most of the time it succeeds 13338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // since we can avoid writing to storage 13348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { 13358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) 13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds = &storage; 13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1339a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1340a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com uint8_t* aa = (uint8_t*)glyph.fImage; 13418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // can't rasterize glyph 13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 13496c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = aa; 13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, *bounds); 13528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, 1355f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1356f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1357f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1358f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!state.fClip->isRect()); 13618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 13698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 13708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 13728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 13738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 13748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1380a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 13818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 13826c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 13838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 13848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 13858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_Bounder(const SkDraw1Glyph& state, 1392f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1393f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1394f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1395f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 14018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 14028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 14048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 14058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 14078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 14088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 14098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 14118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1415d055c1fde2128514167b315f4d104b177e04a3dereed@android.com 1416d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // we need to pass the origin, which we approximate with our 1417d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // (unadjusted) left,top coordinates (the caller called fixedfloor) 1418d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (state.fBounder->doIRectGlyph(cr, 1419d055c1fde2128514167b315f4d104b177e04a3dereed@android.com left - glyph.fLeft, 1420d055c1fde2128514167b315f4d104b177e04a3dereed@android.com top - glyph.fTop, glyph)) { 14218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 14226c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 14238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 14268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1432fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool hasCustomD1GProc(const SkDraw& draw) { 1433fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return draw.fProcs && draw.fProcs->fD1GProc; 1434fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1435fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 1436fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool needsRasterTextBlit(const SkDraw& draw) { 1437fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return !hasCustomD1GProc(draw); 1438fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1439fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 14408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, 14418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache) { 14428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDraw = draw; 14438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBounder = draw->fBounder; 14448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = draw->fClip; 14458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClipBounds = fClip->getBounds(); 14468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = blitter; 14478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCache = cache; 14488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14491d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*draw)) { 14508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw->fProcs->fD1GProc; 14518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == fBounder) { 14548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isRect()) { 14558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RectClip; 14568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RgnClip; 14588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_Bounder; 14618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 14658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText(const char text[], size_t byteLength, 14678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, const SkPaint& paint) const { 14688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 14698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1470f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 14718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1473dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty()) { 14748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 14788d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 14798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawText_asPaths(text, byteLength, x, y, paint); 14808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 14848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1485f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 14861d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1487f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1488f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1489f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1490f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1491f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1492f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1493f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1494f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 14958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1496a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 14978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform our starting point 14988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 14998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint loc; 1500f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix->mapXY(x, y, &loc); 15018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x = loc.fX; 15028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y = loc.fY; 15038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 15068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 15078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector stop; 15088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com measure_text(cache, glyphCacheProc, text, byteLength, &stop); 15108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopX = stop.fX; 15128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopY = stop.fY; 15138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 15158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopX = SkScalarHalf(stopX); 15168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopY = SkScalarHalf(stopY); 15178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x -= stopX; 15198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y -= stopY; 15208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1521a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(x); 15238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(y); 15248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 15258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1526f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1527f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 15288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 1529cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*matrix); 1530cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == baseline) { 1531f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1532cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == baseline) { 1533f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 15348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1536f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // apply the bias here, so we don't have to add 1/2 in the loop 1537f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx += SK_FixedHalf; 1538f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fy += SK_FixedHalf; 15398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15401d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 15411d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 15421d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 15431d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 15441d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 15458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 154652c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkDraw1Glyph d1g; 154752c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 15488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1550f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 15518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += autokern.adjust(glyph); 15538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 155552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com proc(d1g, fx, fy, glyph); 15568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += glyph.fAdvanceX; 15588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy += glyph.fAdvanceY; 15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// last parameter is interpreted as SkFixed [x, y] 15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// return the fixed position, which may be rounded or not by the caller 15648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// e.g. subpixel doesn't round 15658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); 15668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); 15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), 15758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); 15768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, 15798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 15808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, 15818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - glyph.fAdvanceY); 15828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic AlignProc pick_align_proc(SkPaint::Align align) { 15858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const AlignProc gProcs[] = { 15868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com leftAlignProc, centerAlignProc, rightAlignProc 15878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1588a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); 15908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return gProcs[align]; 15928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass TextMapState { 15958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 15968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPoint fLoc; 1597a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState(const SkMatrix& matrix, SkScalar y) 15998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} 16008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); 1602a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc pickProc(int scalarsPerPosition); 1604a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 16068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& fMatrix; 16078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc fProc; 16088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fY; // ignored by MapXYProc 16098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // these are only used by Only... procs 16108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fScaleX, fTransX, fTransformedY; 16118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXProc(const TextMapState& state, const SkScalar pos[]) { 16138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc); 16148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1615a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXYProc(const TextMapState& state, const SkScalar pos[]) { 16178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc); 16188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1619a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyScaleXProc(const TextMapState& state, 16218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX, 16238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fTransformedY); 16248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1625a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyTransXProc(const TextMapState& state, 16278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(*pos + state.fTransX, state.fTransformedY); 16298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 16318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comTextMapState::Proc TextMapState::pickProc(int scalarsPerPosition) { 16338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1634a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (1 == scalarsPerPosition) { 16368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned mtype = fMatrix.getType(); 16378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 16388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXProc; 16398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 16408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fScaleX = fMatrix.getScaleX(); 16418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransX = fMatrix.getTranslateX(); 16428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) + 16438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix.getTranslateY(); 16448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (mtype & SkMatrix::kScale_Mask) ? 16458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MapOnlyScaleXProc : MapOnlyTransXProc; 16468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXYProc; 16498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 16538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPosText(const char text[], size_t byteLength, 16558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[], SkScalar constY, 16568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scalarsPerPosition, const SkPaint& paint) const { 16578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 16588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 16598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1660f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 16618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1663dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty()) { 16648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 16658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 16688d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 16698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // TODO !!!! 16708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// this->drawText_asPaths(text, byteLength, x, y, paint); 16718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 16728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1674f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 16751d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1676f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1677f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1678f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1679f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1680f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1681f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1682a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1684f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 16858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1686a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16871d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 16881d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 16891d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 16901d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 16911d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 16928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 16938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com AlignProc alignProc = pick_align_proc(paint.getTextAlign()); 16948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph d1g; 16958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 1696f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com TextMapState tms(*matrix, constY); 16978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); 16988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 17008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // maybe we should skip the rounding if linearText is set 1701cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment roundBaseline = SkComputeAxisAlignmentForHText(*matrix); 17028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkPaint::kLeft_Align == paint.getTextAlign()) { 17048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1705a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1707a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(tms.fLoc.fX); 17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(tms.fLoc.fY); 1710f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1711f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1713cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1714f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1715cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1716f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1718a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1719f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 1720f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx & fxMask, fy & fyMask); 1721a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 1723f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, glyph); 17248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph* glyph = &glyphCacheProc(cache, &text, 0, 0); 1730a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph->fWidth) { 17328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvX = glyph->fAdvanceX;) 17338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvY = glyph->fAdvanceY;) 17348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx, fy; 1736f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1737f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1739a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 17418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 17428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, *glyph, &fixedLoc); 17438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx = fixedLoc.fX; 17448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy = fixedLoc.fY; 17458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1746cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1747f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1748cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1749f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1752a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // have to call again, now that we've been "aligned" 1754f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com glyph = &glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 17558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the assumption is that the advance hasn't changed 17568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvX == glyph->fAdvanceX); 17578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvY == glyph->fAdvanceY); 1758a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1759f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, *glyph); 17608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // not subpixel 17658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the last 2 parameters are ignored 17678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1768a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 17708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1771a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 17738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, glyph, &fixedLoc); 1774a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1775f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fixedLoc.fX + SK_FixedHalf, 1776f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fixedLoc.fY + SK_FixedHalf, glyph); 17778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 17828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined _WIN32 && _MSC_VER >= 1300 17848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( pop ) 17858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 17868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 17888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathMeasure.h" 17908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpoints(SkPoint dst[], const SkPoint src[], int count, 17928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure& meas, const SkMatrix& matrix) { 17938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc proc = matrix.getMapXYProc(); 17948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 17968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pos; 17978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector tangent; 17988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(matrix, src[i].fX, src[i].fY, &pos); 18008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = pos.fX; 18018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = pos.fY; 18028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com meas.getPosTan(sx, &pos, &tangent); 18048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* This is the old way (that explains our approach but is way too slow 18068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 18078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pt; 18088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pt.set(sx, sy); 18108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setSinCos(tangent.fY, tangent.fX); 18118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.preTranslate(-sx, 0); 18128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(pos.fX, pos.fY); 18138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapPoints(&dst[i], &pt, 1); 18148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 18158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy), 18168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos.fY + SkScalarMul(tangent.fX, sy)); 18178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* TODO 18218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Need differentially more subdivisions when the follow-path is curvy. Not sure how to 18238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com determine that, but we need it. I guess a cheap answer is let the caller tell us, 18248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out. 18258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 18268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, 18278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix) { 18288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Iter iter(src, false); 18298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint srcP[4], dstP[3]; 18308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Verb verb; 18318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { 18338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (verb) { 18348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kMove_Verb: 18358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 1, meas, matrix); 18368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->moveTo(dstP[0]); 18378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kLine_Verb: 18398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // turn lines into quads to look bendy 18408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX); 18418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY); 18428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 2, meas, matrix); 18438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 18448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kQuad_Verb: 18468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 2, meas, matrix); 18478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 18488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kCubic_Verb: 18508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 3, meas, matrix); 18518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->cubicTo(dstP[0], dstP[1], dstP[2]); 18528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kClose_Verb: 18548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->close(); 18558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 18578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"unknown verb"); 18588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 18598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawTextOnPath(const char text[], size_t byteLength, 18648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& follow, const SkMatrix* matrix, 18658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 18668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 18678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1869dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty()) { 18708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 18718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 18748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure meas(follow, false); 18758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar hOffset = 0; 18768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 18788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 18798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar pathLen = meas.getLength(); 18808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 18818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathLen = SkScalarHalf(pathLen); 18828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hOffset += pathLen; 18848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 18878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos; 18888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix scaledMatrix; 18898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar scale = iter.getPathScale(); 18908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scaledMatrix.setScale(scale, scale); 1892a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 18948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 18958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m(scaledMatrix); 18968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postTranslate(xpos + hOffset, 0); 18988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (matrix) { 18998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postConcat(*matrix); 19008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpath(&tmp, *iterPath, meas, m); 1902f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1903f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); 1904f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1905f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(tmp, iter.getPaint(), NULL, true); 1906f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 19078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1910cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#ifdef ANDROID 1911cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.comvoid SkDraw::drawPosTextOnPath(const char text[], size_t byteLength, 1912cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPoint pos[], const SkPaint& paint, 1913cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath& path, const SkMatrix* matrix) const { 1914cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // nothing to draw 1915dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty()) { 1916cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return; 1917cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1918cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1919cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix scaledMatrix; 1920cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPathMeasure meas(path, false); 1921cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1922cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc( 1923cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint::kForward_TextBufferDirection, true); 1924cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1925cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Copied (modified) from SkTextToPathIter constructor to setup paint 1926cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint tempPaint(paint); 1927cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1928cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setLinearText(true); 1929cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup 1930cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1931cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (tempPaint.getPathEffect() == NULL && !(tempPaint.getStrokeWidth() > 0 1932cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com && tempPaint.getStyle() != SkPaint::kFill_Style)) { 1933cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setStyle(SkPaint::kFill_Style); 1934cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setPathEffect(NULL); 1935cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1936cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // End copied from SkTextToPathIter constructor 1937cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1938cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // detach cache 1939cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache* cache = tempPaint.detachCache(NULL); 1940cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1941cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Must set scale, even if 1 1942cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkScalar scale = SK_Scalar1; 1943cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com scaledMatrix.setScale(scale, scale); 1944cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1945cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Loop over all glyph ids 1946cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for (const char* stop = text + byteLength; text < stop; pos++) { 1947cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1948cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkGlyph& glyph = glyphCacheProc(cache, &text); 1949cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPath tmp; 1950cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1951cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath* glyphPath = cache->findPath(glyph); 1952cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (glyphPath == NULL) { 1953cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com continue; 1954cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1955cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1956cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix m(scaledMatrix); 1957cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postTranslate(pos->fX, 0); 1958cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1959cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (matrix) { 1960cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postConcat(*matrix); 1961cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1962cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1963cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com morphpath(&tmp, *glyphPath, meas, m); 1964cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com this->drawPath(tmp, tempPaint); 1965cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1966cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1967cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1968cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // re-attach cache 1969cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache::AttachCache(cache); 1970cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com} 1971cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif 1972cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 19738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 19748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct VertState { 19768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int f0, f1, f2; 19778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState(int vCount, const uint16_t indices[], int indexCount) 19798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fIndices(indices) { 19808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCurrIndex = 0; 19818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (indices) { 19828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = indexCount; 19838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 19848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = vCount; 19858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1987a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1988a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com typedef bool (*Proc)(VertState*); 19898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkCanvas::VertexMode mode); 19908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 19928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCount; 19938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCurrIndex; 19948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* fIndices; 1995a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 19968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool Triangles(VertState*); 19978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TrianglesX(VertState*); 19988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStrip(VertState*); 19998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStripX(VertState*); 20008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFan(VertState*); 20018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFanX(VertState*); 20028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 20038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::Triangles(VertState* state) { 20058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TrianglesX(VertState* state) { 20178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStrip(VertState* state) { 20308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 20368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 1; 20378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 0; 20388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStripX(VertState* state) { 20478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 20548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 1]; 20558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 0]; 20568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFan(VertState* state) { 20658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = 0; 20708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFanX(VertState* state) { 20778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[0]; 20838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 20868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comVertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { 20908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 20918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangles_VertexMode: 20928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TrianglesX : Triangles; 20938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleStrip_VertexMode: 20948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleStripX : TriangleStrip; 20958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleFan_VertexMode: 20968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleFanX : TriangleFan; 20978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 20988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 20998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRegion*, 21038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 21048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic HairProc ChooseHairProc(bool doAntiAlias) { 21068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; 21078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool texture_to_matrix(const VertState& state, const SkPoint verts[], 21108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint texs[], SkMatrix* matrix) { 21118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src[3], dst[3]; 2112a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[0] = texs[state.f0]; 21148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[1] = texs[state.f1]; 21158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[2] = texs[state.f2]; 21168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[0] = verts[state.f0]; 21178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[1] = verts[state.f1]; 21188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[2] = verts[state.f2]; 21198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return matrix->setPolyToPoly(src, dst, 3); 21208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkTriColorShader : public SkShader { 21238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 21248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader() {} 21258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); 2127a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count); 2129a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 21318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader(SkFlattenableReadBuffer& buffer) : SkShader(buffer) {} 2132a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 2134a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 21368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix fDstToUnit; 21378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor fColors[3]; 2138a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 21408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkTriColorShader, (buffer)); 21418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkShader INHERITED; 21438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 21448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkTriColorShader::setup(const SkPoint pts[], const SkColor colors[], 21468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index0, int index1, int index2) { 2147a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[0] = SkPreMultiplyColor(colors[index0]); 21498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[1] = SkPreMultiplyColor(colors[index1]); 21508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[2] = SkPreMultiplyColor(colors[index2]); 2151a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m, im; 21538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 21548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(0, pts[index1].fX - pts[index0].fX); 21558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(1, pts[index2].fX - pts[index0].fX); 21568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(2, pts[index0].fX); 21578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(3, pts[index1].fY - pts[index0].fY); 21588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(4, pts[index2].fY - pts[index0].fY); 21598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(5, pts[index0].fY); 21608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!m.invert(&im)) { 21618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fDstToUnit.setConcat(im, this->getTotalInverse()); 21648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 2167689411a87ca7d19abe04b5c9baff26bd96b2123ereed@android.com#include "SkComposeShader.h" 21688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic int ScalarTo256(SkScalar v) { 21708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale = SkScalarToFixed(v) >> 8; 21718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale < 0) { 21728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 0; 21738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale > 255) { 21758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 255; 21768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkAlpha255To256(scale); 21788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkTriColorShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { 21818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src; 2182a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 21848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 21858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += 1; 2186a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale1 = ScalarTo256(src.fX); 21888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale2 = ScalarTo256(src.fY); 21898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale0 = 256 - scale1 - scale2; 21908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale0 < 0) { 21918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale1 > scale2) { 21928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale2 = 256 - scale1; 21938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale1 = 256 - scale2; 21958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale0 = 0; 21978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2198a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 22008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[1], scale1) + 22018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[2], scale2); 22028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, 22068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint textures[], 22078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 22088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 22098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 22108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == count || NULL != vertices); 2211a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // abort early if there is nothing to draw 2213dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com if (count < 3 || (indices && indexCount < 3) || fClip->isEmpty()) { 22148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2216a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform out vertices into device coordinates 22188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoSTMalloc<16, SkPoint> storage(count); 22198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint* devVerts = storage.get(); 22208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapPoints(devVerts, vertices, count); 2221a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder) { 22238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 22248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(devVerts, count); 22258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!fBounder->doRect(bounds, paint)) { 22268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2229a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 22318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com We can draw the vertices in 1 of 4 ways: 22328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - solid color (no shader/texture[], no colors[]) 22348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just colors (no shader/texture[], has colors[]) 22358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just texture (has shader/texture[], no colors[]) 22368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - colors * texture (has shader/texture[], has colors[]) 2237a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Thus for texture drawing, we need both texture[] and a shader. 22398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 22408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader triShader; // must be above declaration of p 22428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 22438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* shader = p.getShader(); 22458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == shader) { 22468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we have no shader, we ignore the texture coordinates 22478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textures = NULL; 22488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (NULL == textures) { 22498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we don't have texture coordinates, ignore the shader 22508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(NULL); 22518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader = NULL; 22528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup the custom shader (if needed) 22558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 22568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == textures) { 22578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // just colors (no texture) 22588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(&triShader); 22598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 22608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // colors * texture 22618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(shader); 22628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool releaseMode = false; 22638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == xmode) { 2264845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com xmode = SkXfermode::Create(SkXfermode::kMultiply_Mode); 22658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com releaseMode = true; 22668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* compose = SkNEW_ARGS(SkComposeShader, 22688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (&triShader, shader, xmode)); 22698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(compose)->unref(); 22708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (releaseMode) { 22718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xmode->unref(); 22728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); 22778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup our state and function pointer for iterating triangles 22788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState state(count, indices, indexCount); 22798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState::Proc vertProc = state.chooseProc(vmode); 2280a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures || NULL != colors) { 22828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix localM, tempM; 22838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasLocalM = shader && shader->getLocalMatrix(&localM); 2284a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 22868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setContext(*fBitmap, p, *fMatrix)) { 22878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colors = NULL; 22888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2290a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 22928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures) { 22938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (texture_to_matrix(state, vertices, textures, &tempM)) { 22948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 22958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tempM.postConcat(localM); 22968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(tempM); 22988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to recal setContext since we changed the local matrix 22998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!shader->setContext(*fBitmap, p, *fMatrix)) { 23008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setup(vertices, colors, 23068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.f0, state.f1, state.f2)) { 23078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillTriangle(devVerts[state.f0], devVerts[state.f1], 23118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devVerts[state.f2], fClip, blitter.get()); 23128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now restore the shader's original local matrix 23148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != shader) { 23158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(localM); 23178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->resetLocalMatrix(); 23198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // no colors[] and no texture 23238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); 23248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 23258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f0], devVerts[state.f1], fClip, blitter.get()); 23268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f1], devVerts[state.f2], fClip, blitter.get()); 23278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f2], devVerts[state.f0], fClip, blitter.get()); 23288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23320a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23330a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 23368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2337f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkDraw::validate() const { 23388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fBitmap != NULL); 23398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fMatrix != NULL); 23408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fClip != NULL); 23418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = fClip->getBounds(); 23438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect br; 23448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2345f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com br.set(0, 0, fBitmap->width(), fBitmap->height()); 23468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(cr.isEmpty() || br.contains(cr)); 2347f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 2348f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // assert that both are null, or both are not-null 2349f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkASSERT(!fMVMatrix == !fExtMatrix); 23508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 23538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23540a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 23550a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com 23560a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.comSkBounder::SkBounder() { 23570a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com // initialize up front. This gets reset by SkCanvas before each draw call. 23580a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com fClip = &SkRegion::GetEmptyRegion(); 23590a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com} 23608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doIRect(const SkIRect& r) { 23628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect rr; 23638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return rr.intersect(fClip->getBounds(), r) && this->onIRect(rr); 23648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 23658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2366d055c1fde2128514167b315f4d104b177e04a3dereed@android.com// TODO: change the prototype to take fixed, and update the callers 2367d055c1fde2128514167b315f4d104b177e04a3dereed@android.combool SkBounder::doIRectGlyph(const SkIRect& r, int x, int y, 2368d055c1fde2128514167b315f4d104b177e04a3dereed@android.com const SkGlyph& glyph) { 2369474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com SkIRect rr; 2370d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (!rr.intersect(fClip->getBounds(), r)) { 2371d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return false; 2372d055c1fde2128514167b315f4d104b177e04a3dereed@android.com } 2373d055c1fde2128514167b315f4d104b177e04a3dereed@android.com GlyphRec rec; 2374d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.set(SkIntToFixed(x), SkIntToFixed(y)); 2375d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fRSB.set(rec.fLSB.fX + glyph.fAdvanceX, 2376d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.fY + glyph.fAdvanceY); 2377d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fGlyphID = glyph.getGlyphID(); 2378d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fFlags = 0; 2379d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return this->onIRectGlyph(rr, rec); 2380474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com} 2381474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com 23828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doHairline(const SkPoint& pt0, const SkPoint& pt1, 23838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 23848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 23858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar v0, v1; 23868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fX; 23888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fX; 23898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 23908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 23918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = SkScalarFloor(v0); 23938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = SkScalarCeil(v1); 23948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fY; 23968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fY; 23978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 23988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 23998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = SkScalarFloor(v0); 24018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = SkScalarCeil(v1); 24028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doRect(const SkRect& rect, const SkPaint& paint) { 24108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getStyle() == SkPaint::kFill_Style) { 24138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.round(&r); 24148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 24158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rad = -1; 24168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.roundOut(&r); 24178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rad = -2; 24198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(rad, rad); 24218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doPath(const SkPath& path, const SkPaint& paint, bool doFill) { 2426d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkIRect r; 2427d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& bounds = path.getBounds(); 24288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 24308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.round(&r); 24318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 24328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&r); 24338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkBounder::commit() { 24428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override in subclass 24438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////////////////////// 24468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 24488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 24498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 24508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 24518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, 24538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 24548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds) { 24558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (devPath.isEmpty()) { 24568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 24578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // init our bounds from the path 24608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2461d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkRect pathBounds = devPath.getBounds(); 24628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); 24638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.roundOut(bounds); 24648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2465a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24665af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIPoint margin; 24678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (filter) { 24688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(filterMatrix); 2469a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24705af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkMask srcM, dstM; 2471a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fBounds = *bounds; 24738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fFormat = SkMask::kA8_Format; 24748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fImage = NULL; 24758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { 24768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 24778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2479a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 24805af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com // (possibly) trim the bounds to reflect the clip 24818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (plus whatever slop the filter needs) 24825af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (clipBounds) { 24835af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIRect tmp = *clipBounds; 24843555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // Ugh. Guard against gigantic margins from wacky filters. Without this 24853555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // check we can request arbitrary amounts of slop beyond our visible 24863555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // clip, and bring down the renderer (at least on finite RAM machines 24873555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // like handsets, etc.). Need to balance this invented value between 24883555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // quality of large filters like blurs, and the corresponding memory 24893555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // requests. 24903555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com static const int MAX_MARGIN = 128; 24913555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), 24923555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com -SkMin32(margin.fY, MAX_MARGIN)); 24935af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (!bounds->intersect(tmp)) { 24945af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com return false; 24955af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com } 24968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 24998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void draw_into_mask(const SkMask& mask, const SkPath& devPath) { 25028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap bm; 25038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw; 25048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion clipRgn; 25058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 25068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint paint; 25078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height(), mask.fRowBytes); 25098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setPixels(mask.fImage); 25108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRgn.setRect(0, 0, mask.fBounds.width(), mask.fBounds.height()); 25128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), 25138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 25148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBitmap = &bm; 25168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fClip = &clipRgn; 25178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 25188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBounder = NULL; 25198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.setAntiAlias(true); 25208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawPath(devPath, paint); 25218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 25248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 25258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask* mask, SkMask::CreateMode mode) { 25268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustRenderImage_CreateMode != mode) { 25278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds)) 25288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2530a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { 25328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fFormat = SkMask::kA8_Format; 25338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fRowBytes = mask->fBounds.width(); 2534543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask->computeImageSize(); 2535543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 2536543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // we're too big to allocate the mask, abort 2537543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return false; 2538543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 2539543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com mask->fImage = SkMask::AllocImage(size); 25408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask->fImage, 0, mask->computeImageSize()); 25418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustComputeBounds_CreateMode != mode) { 25448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_into_mask(*mask, devPath); 25458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2546a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 25488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2549