SkDraw.cpp revision 83a444602ec580a0040713eed588c245b4ae0ee9
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" 19045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com#include "SkRasterClip.h" 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRasterizer.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScan.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h" 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStroke.h" 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTemplatesPriv.h" 2532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com#include "SkTLazy.h" 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAutoKern.h" 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmapProcShader.h" 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawProcs.h" 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//#define TRACE_BITMAP_DRAWS 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define kBlitterStorageLongCount (sizeof(SkBitmapProcShader) >> 2) 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 36fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com/** Helper for allocating small blitters on the stack. 37fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com */ 3840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBlitterChoose : SkNoncopyable { 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 401d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose() { 411d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = NULL; 421d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = SkBlitter::Choose(device, matrix, paint, 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage)); 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 481d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBlitterChoose(); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* operator->() { return fBlitter; } 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* get() const { return fBlitter; } 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 541d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com void choose(const SkBitmap& device, const SkMatrix& matrix, 551d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com const SkPaint& paint) { 561d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkASSERT(!fBlitter); 571d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = SkBlitter::Choose(device, matrix, paint, 581d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fStorage, sizeof(fStorage)); 591d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 601d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* fBlitter; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fStorage[kBlitterStorageLongCount]; 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAutoBlitterChoose::~SkAutoBlitterChoose() { 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)fBlitter == (void*)fStorage) { 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter->~SkBlitter(); 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(fBlitter); 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com/** 7540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * Since we are providing the storage for the shader (to avoid the perf cost 7640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * of calling new) we insist that in our destructor we can account for all 7740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * owners of the shader. 7840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com */ 7940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBitmapShaderInstall : SkNoncopyable { 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 8140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) 8240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com : fPaint(paint) /* makes a copy of the paint */ { 8340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(SkShader::CreateBitmapShader(src, 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage))); 8640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // we deliberately left the shader with an owner-count of 2 8740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == fPaint.getShader()->getRefCnt()); 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8982065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBitmapShaderInstall() { 9140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkShader* shader = fPaint.getShader(); 9240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // since we manually destroy shader, we insist that owners == 2 9340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == shader->getRefCnt()); 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(NULL); // unref the shader by 1 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // now destroy to take care of the 2nd owner-count 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)shader == (void*)fStorage) { 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->~SkShader(); 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(shader); 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10482065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 10540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // return the new paint that has the shader applied 10640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& paintWithShader() const { return fPaint; } 10782065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 10940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint fPaint; // copy of caller's paint (which we then modify) 11040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com uint32_t fStorage[kBlitterStorageLongCount]; 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 115f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comSkDraw::SkDraw() { 116f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com sk_bzero(this, sizeof(*this)); 117f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 118f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw::SkDraw(const SkDraw& src) { 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memcpy(this, &src, sizeof(*this)); 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*BitmapXferProc)(void* pixels, size_t bytes, uint32_t data); 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Clear_BitmapXferProc(void* pixels, size_t bytes, uint32_t) { 1284516f4786f5dda1b86a8f825b9e8e910d9c2363creed@android.com sk_bzero(pixels, bytes); 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Dst_BitmapXferProc(void*, size_t, uint32_t data) {} 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D32_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset32((uint32_t*)pixels, data, bytes >> 2); 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D16_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset16((uint16_t*)pixels, data, bytes >> 1); 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(pixels, data, bytes); 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap, 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t* data) { 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // todo: we can apply colorfilter up front if no shader, so we wouldn't 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to abort this fastpath 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getShader() || paint.getColorFilter()) { 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 154845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode; 155845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (!SkXfermode::IsMode(paint.getXfermode(), &mode)) { 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 158a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColor color = paint.getColor(); 160a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // collaps modes based on color... 162845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (SkXfermode::kSrcOver_Mode == mode) { 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned alpha = SkColorGetA(color); 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == alpha) { 165845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kDst_Mode; 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (0xFF == alpha) { 167845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kSrc_Mode; 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 170a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 172845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kClear_Mode: 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Clear_BitmapXferProc\n"); 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Clear_BitmapXferProc; // ignore data 175845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kDst_Mode: 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Dst_BitmapXferProc\n"); 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Dst_BitmapXferProc; // ignore data 178845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kSrc_Mode: { 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 180a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com should I worry about dithering for the lower depths? 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor pmc = SkPreMultiplyColor(color); 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = pmc; 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D32_Src_BitmapXferProc\n"); 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D32_Src_BitmapXferProc; 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel4444(pmc); 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel16(pmc); 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkGetPackedA32(pmc); 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- DA8_Src_BitmapXferProc\n"); 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return DA8_Src_BitmapXferProc; 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com BitmapXferProc proc, uint32_t procData) { 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int shiftPerPixel; 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 2; 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 1; 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 0; 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"Can't use xferproc on this config"); 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t* pixels = (uint8_t*)bitmap.getPixels(); 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pixels); 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t rowBytes = bitmap.rowBytes(); 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const int widthBytes = rect.width() << shiftPerPixel; 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // skip down to the first scanline and X position 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rect.fTop * rowBytes + (rect.fLeft << shiftPerPixel); 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int scans = rect.height() - 1; scans >= 0; --scans) { 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(pixels, widthBytes, procData); 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rowBytes; 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPaint(const SkPaint& paint) const { 252f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 254045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty()) { 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devRect; 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.set(0, 0, fBitmap->width(), fBitmap->height()); 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(devRect)) { 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 263a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 264045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isBW()) { 265045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com /* If we don't have a shader (i.e. we're just a solid color) we may 266045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com be faster to operate directly on the device bitmap, rather than invoking 267045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com a blitter. Esp. true for xfermodes, which require a colorshader to be 268045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com present, which is just redundant work. Since we're drawing everywhere 269045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com in the clip, we don't have to worry about antialiasing. 270045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com */ 271045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com uint32_t procData = 0; // to avoid the warning 272045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData); 273045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (proc) { 274045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (D_Dst_BitmapXferProc == proc) { // nothing to do 275045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return; 276045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 277a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 278045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkRegion::Iterator iter(fRC->bwRgn()); 279045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com while (!iter.done()) { 280045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData); 281045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com iter.next(); 282045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 283045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return; 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 286045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 287045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com // normal case: use a blitter 288045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 289045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::FillIRect(devRect, *fRC, blitter.get()); 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct PtProcRec { 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas::PointMode fMode; 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* fPaint; 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* fClip; 298045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkRasterClip* fRC; 299a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // computed values 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fRadius; 302a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const PtProcRec&, const SkPoint devPts[], int count, 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool init(SkCanvas::PointMode, const SkPaint&, const SkMatrix* matrix, 307045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkRasterClip*); 308045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com Proc chooseProc(SkBlitter** blitter); 309045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 310045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comprivate: 311045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAAClipBlitterWrapper fWrapper; 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(rec.fClip->isRect()); 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& r = rec.fClip->getBounds(); 318a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_16_hair_proc(const PtProcRec& rec, 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint devPts[], int count, 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter) { 331045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkASSERT(rec.fRC->isRect()); 332045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkIRect& r = rec.fRC->getBounds(); 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap); 336a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint16_t* addr = bitmap->getAddr16(0, 0); 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rb = bitmap->rowBytes(); 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// *bitmap->getAddr16(x, y) = SkToU16(value); 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ((uint16_t*)((char*)addr + y * rb))[x] = SkToU16(value); 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (rec.fClip->contains(x, y)) { 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 364045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 371045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// aa versions 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 380045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 387045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// square procs (strokeWidth > 0 but matrix is square-scale (sx == sy) 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[], 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 399a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 405a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 406045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::FillXRect(r, *rec.fRC, blitter); 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[], 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 416a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 422a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 423045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::AntiFillXRect(r, *rec.fRC, blitter); 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 427b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com// If this guy returns true, then chooseProc() must return a valid proc 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint, 429045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkMatrix* matrix, const SkRasterClip* rc) { 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect()) { 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width = paint.getStrokeWidth(); 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == width) { 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 437045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = NULL; 438045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fRC = rc; 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SK_Fixed1 >> 1; 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 442b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com if (paint.getStrokeCap() != SkPaint::kRound_Cap && 443b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com matrix->rectStaysRect() && SkCanvas::kPoints_PointMode == mode) { 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = matrix->get(SkMatrix::kMScaleX); 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = matrix->get(SkMatrix::kMScaleY); 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkScalarNearlyZero(sx - sy)) { 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (sx < 0) { 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sx = -sx; 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 453045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = NULL; 454045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fRC = rc; 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 462045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comPtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) { 463b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com Proc proc = NULL; 464a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 465045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBlitter* blitter = *blitterPtr; 466045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isBW()) { 467045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = &fRC->bwRgn(); 468045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } else { 469045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fWrapper.init(*fRC, blitter); 470045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = &fWrapper.getRgn(); 471045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = fWrapper.getBlitter(); 472045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com *blitterPtr = blitter; 473045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 474045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // for our arrays 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == SkCanvas::kPoints_PointMode); 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == SkCanvas::kLines_PointMode); 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(2 == SkCanvas::kPolygon_PointMode); 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)fMode <= (unsigned)SkCanvas::kPolygon_PointMode); 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // first check for hairlines 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == fPaint->getStrokeWidth()) { 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const Proc gAAProcs[] = { 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa_square_proc, aa_line_hair_proc, aa_poly_hair_proc 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gAAProcs[fMode]; 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bm = blitter->justAnOpaqueColor(&value); 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bm && bm->config() == SkBitmap::kRGB_565_Config) { 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_16_hair_proc; 4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_hair_proc; 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static Proc gBWProcs[] = { 4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gBWProcs[fMode]; 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 504b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) { 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(SkCanvas::kPoints_PointMode == fMode); 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = aa_square_proc; 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_square_proc; 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return proc; 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool bounder_points(SkBounder* bounder, SkCanvas::PointMode mode, 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t count, const SkPoint pts[], 5178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, const SkMatrix& matrix) { 5188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ibounds; 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar inset = paint.getStrokeWidth(); 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(pts, count); 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.inset(-inset, -inset); 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapRect(&bounds); 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&ibounds); 5278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return bounder->doIRect(ibounds); 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// each of these costs 8-bytes of stack space, so don't make it too large 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// must be even for lines/polygon to work 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define MAX_DEV_PTS 32 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count, 535f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPoint pts[], const SkPaint& paint, 536f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com bool forceUseDevice) const { 5378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we're in lines mode, force count to be even 5388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kLines_PointMode == mode) { 5398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count &= ~(size_t)1; 5408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((long)count <= 0) { 5438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 545a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pts != NULL); 547f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 548a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 550045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty()) { 5518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 554fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (fBounder) { 555fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (!bounder_points(fBounder, mode, count, pts, paint, *fMatrix)) { 556fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 557fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 558fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 559fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // clear the bounder and call this again, so we don't invoke the bounder 560fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // later if we happen to call ourselves for drawRect, drawPath, etc. 561fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com SkDraw noBounder(*this); 562fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.fBounder = NULL; 563fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.drawPoints(mode, count, pts, paint, forceUseDevice); 564fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 565fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 566fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec rec; 568045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint devPts[MAX_DEV_PTS]; 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* bltr = blitter.get(); 574045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com PtProcRec::Proc proc = rec.chooseProc(&bltr); 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we have to back up subsequent passes if we're in polygon mode 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t backup = (SkCanvas::kPolygon_PointMode == mode); 577a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 5798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t n = count; 5808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (n > MAX_DEV_PTS) { 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com n = MAX_DEV_PTS; 5828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix->mapPoints(devPts, pts, n); 5848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(rec, devPts, n, bltr); 5858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pts += n - backup; 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(count >= n); 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= n; 5888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count > 0) { 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count += backup; 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (count != 0); 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 5948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPoints_PointMode: { 5958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // temporarily mark the paint as filling. 59640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint newPaint(paint); 59740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com newPaint.setStyle(SkPaint::kFill_Style); 5988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 59940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkScalar width = newPaint.getStrokeWidth(); 6008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar radius = SkScalarHalf(width); 601a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 60240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix preMatrix; 605a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.addCircle(0, 0, radius); 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preMatrix.setTranslate(pts[i].fX, pts[i].fY); 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // pass true for the last point, since we can modify 6108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // then path then 611f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 61240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawPath(*this, path, newPaint, &preMatrix, 613f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com (count-1) == i); 614f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 61540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawPath(path, newPaint, &preMatrix, 61640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (count-1) == i); 617f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 621a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = pts[i].fX - radius; 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = pts[i].fY - radius; 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = r.fLeft + width; 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = r.fTop + width; 627f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 62840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawRect(*this, r, newPaint); 629f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 63040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawRect(r, newPaint); 631f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kLines_PointMode: 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPolygon_PointMode: { 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= 1; 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStyle(SkPaint::kStroke_Style); 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i += inc) { 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.moveTo(pts[i]); 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.lineTo(pts[i+1]); 646f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 647f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, path, p, NULL, true); 648f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 649f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(path, p, NULL, true); 650f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.rewind(); 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_lefttop(SkRect* r) { 6608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkPoint*)(void*)r; 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_rightbottom(SkRect* r) { 6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return ((SkPoint*)(void*)r) + 1; 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 667761fb62b0eb174783316d2a8b933fba896ca6355reed@google.comstatic bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, 668761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint* strokeSize) { 669761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com if (SkPaint::kMiter_Join != paint.getStrokeJoin() || 670761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com paint.getStrokeMiter() < SK_ScalarSqrt2) { 671761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return false; 672761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com } 67362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 674761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkASSERT(matrix.rectStaysRect()); 675761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() }; 676761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com matrix.mapVectors(strokeSize, &pt, 1); 6776115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fX = SkScalarAbs(strokeSize->fX); 6786115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fY = SkScalarAbs(strokeSize->fY); 679761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return true; 6807ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org} 6817ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 68262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comSkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, 68362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const SkMatrix& matrix, 68462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint* strokeSize) { 6857ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org RectType rtype; 6867ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org const SkScalar width = paint.getStrokeWidth(); 68762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const bool zeroWidth = (0 == width); 6887ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::Style style = paint.getStyle(); 68962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6907ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) { 6917ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org style = SkPaint::kFill_Style; 6927ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 69362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect() || paint.getMaskFilter() || 69562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com paint.getRasterizer() || !matrix.rectStaysRect() || 6967ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::kStrokeAndFill_Style == style) { 69762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 69862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (SkPaint::kFill_Style == style) { 6997ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kFill_RectType; 7007ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else if (zeroWidth) { 7017ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kHair_RectType; 70262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (easy_rect_join(paint, matrix, strokeSize)) { 7037ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kStroke_RectType; 7047ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7057ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kPath_RectType; 7067ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 70762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return rtype; 70862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com} 70962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 71040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comstatic SkPoint* rect_points(SkRect& r, int index) { 71140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT((unsigned)index < 2); 71240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com return &((SkPoint*)(void*)&r)[index]; 71340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com} 71440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com 71562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comvoid SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const { 71662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkDEBUGCODE(this->validate();) 7177ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 71862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com // nothing to draw 719045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty()) { 72062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return; 72162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 72262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 72362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint strokeSize; 72462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); 72562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 72662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#ifdef SK_DISABLE_FAST_AA_STROKE_RECT 72762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (kStroke_RectType == rtype && paint.isAntiAlias()) { 72862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 72962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 73062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#endif 731045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 7327ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (kPath_RectType == rtype) { 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.addRect(rect); 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.setFillType(SkPath::kWinding_FillType); 736187d5595901d1120d9425851e5afdd773f574502reed@android.com this->drawPath(tmp, paint, NULL, true); 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix = *fMatrix; 7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect devRect; 7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform rect into devRect 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fLeft, rect.fTop, rect_points(devRect, 0)); 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fRight, rect.fBottom, rect_points(devRect, 1)); 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.sort(); 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doRect(devRect, paint)) { 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // look for the quick exit, before we build a blitter 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.roundOut(&ir); 75855e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com if (paint.getStyle() != SkPaint::kFill_Style) { 75955e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com // extra space for hairlines 76055e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com ir.inset(-1, -1); 76155e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com } 762045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->quickReject(ir)) 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitterStorage(*fBitmap, matrix, paint); 767045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkRasterClip& clip = *fRC; 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = blitterStorage.get(); 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 770b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter 771b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // case we are also hairline (if we've gotten to here), which devolves to 772b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // effectively just kFill 7737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org switch (rtype) { 7747ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kFill_RectType: 7757ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7767ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiFillRect(devRect, clip, blitter); 7777ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7787ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::FillRect(devRect, clip, blitter); 7797ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7807ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7817ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kStroke_RectType: 7827ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 783761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::AntiFrameRect(devRect, strokeSize, clip, blitter); 7847ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 785761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::FrameRect(devRect, strokeSize, clip, blitter); 7867ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7877ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7887ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kHair_RectType: 7897ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7907ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiHairRect(devRect, clip, blitter); 7917ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7927ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::HairRect(devRect, clip, blitter); 7937ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7947ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7957ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org default: 7967ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkASSERT(!"bad rtype"); 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (srcM.fBounds.isEmpty()) { 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8050a60b3d32eae945688b69599f11679662657f751bungeman@google.com const SkMask* mask = &srcM; 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8070a60b3d32eae945688b69599f11679662657f751bungeman@google.com SkMask dstM; 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getMaskFilter() && 8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { 8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask = &dstM; 811bf2ac7e52f84095368dc50600fd6e78cc96044e3bungeman@google.com } else { 812bf2ac7e52f84095368dc50600fd6e78cc96044e3bungeman@google.com dstM.fImage = NULL; 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 81402f55841854ae32f21a13417e9ee711463e488cfbungeman@google.com SkAutoMaskFreeImage ami(dstM.fImage); 8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(mask->fBounds)) { 8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 820045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAutoBlitterChoose blitterChooser(*fBitmap, *fMatrix, paint); 821045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBlitter* blitter = blitterChooser.get(); 822045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 823045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAAClipBlitterWrapper wrapper; 824045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkRegion* clipRgn; 8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 826045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isBW()) { 827045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com clipRgn = &fRC->bwRgn(); 828045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } else { 829045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com wrapper.init(*fRC, blitter); 830045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com clipRgn = &wrapper.getRgn(); 831045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = wrapper.getBlitter(); 832045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 833045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter->blitMaskRegion(*mask, *clipRgn); 8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 836ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.comstatic SkScalar fast_len(const SkVector& vec) { 837ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar x = SkScalarAbs(vec.fX); 838ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar y = SkScalarAbs(vec.fY); 839ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com if (x < y) { 840ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkTSwap(x, y); 841ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 842ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return x + SkScalarHalf(y); 843ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 844ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 845ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.comstatic bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) { 846ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkXfermode::Coeff dc; 847ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!SkXfermode::AsCoeff(xfer, NULL, &dc)) { 848ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 849ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 850ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 851ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com switch (dc) { 852ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kOne_Coeff: 853ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISA_Coeff: 854ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com case SkXfermode::kISC_Coeff: 855ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 856ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com default: 857ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 858ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 859ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com} 860ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 861ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.combool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, 862ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha* newAlpha) { 863ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkASSERT(newAlpha); 864ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkPaint::kStroke_Style != paint.getStyle()) { 865ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 866ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 867ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar strokeWidth = paint.getStrokeWidth(); 868ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (0 == strokeWidth) { 869ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = paint.getAlpha(); 870ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return true; 871ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 872ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 873ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // if we get here, we need to try to fake a thick-stroke with a modulated 874ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com // hairline 875ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 876ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!paint.isAntiAlias()) { 877ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 878ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 879ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (!xfermodeSupportsCoverageAsAlpha(paint.getXfermode())) { 880ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com return false; 881ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com } 8828d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com if (matrix.hasPerspective()) { 883ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 884ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 885ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com 886ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkVector src[2], dst[2]; 887ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[0].set(strokeWidth, 0); 888ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com src[1].set(0, strokeWidth); 889ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com matrix.mapVectors(dst, src, 2); 890ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len0 = fast_len(dst[0]); 891ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len1 = fast_len(dst[1]); 892652807bbc8c57e5fa9622126b51fd369f5c67935agl@chromium.org if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { 893ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkScalar modulate = SkScalarAve(len0, len1); 8946a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#if 0 895ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com *newAlpha = SkToU8(SkScalarRoundToInt(modulate * paint.getAlpha())); 8966a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#else 8976a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // this is the old technique, which we preserve for now so we don't 8986a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // change previous results (testing) 8996a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com // the new way seems fine, its just (a tiny bit) different 9006a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com int scale = (int)SkScalarMul(modulate, 256); 9016a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com *newAlpha = paint.getAlpha() * scale >> 8; 9026a87fafc5ce0d7fdf1decf8bb9dd6942f2433addreed@google.com#endif 903ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return true; 904ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 905ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 906ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 907ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 90832e5d97ccf60f859db063ebd6e903c362e625767reed@google.comvoid SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, 9098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* prePathMatrix, bool pathIsMutable) const { 910f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 9118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 913045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty()) { 9148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* pathPtr = (SkPath*)&origSrcPath; 9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool doFill = true; 9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmpPath; 9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix tmpMatrix; 9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (prePathMatrix) { 92432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style || 92532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getRasterizer()) { 9268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* result = pathPtr; 927a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!pathIsMutable) { 9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result = &tmpPath; 9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathIsMutable = true; 9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*prePathMatrix, result); 9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = result; 9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!tmpMatrix.setConcat(*matrix, *prePathMatrix)) { 9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overflow 9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix = &tmpMatrix; 9408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // at this point we're done with prePathMatrix 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) 944a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 94532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com const SkPaint* paint = &origPaint; 94632e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkTLazy<SkPaint> lazyPaint; 947a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 948ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com { 949ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com SkAlpha newAlpha; 950ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com if (SkDrawTreatAsHairline(origPaint, *matrix, &newAlpha)) { 95132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.set(origPaint); 952ecadf99c8450646dfd9c2754f3e845245beab8b6reed@google.com lazyPaint.get()->setAlpha(newAlpha); 95332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.get()->setStrokeWidth(0); 95432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint = lazyPaint.get(); 9558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 957a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 95832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { 95932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com doFill = paint->getFillPath(*pathPtr, &tmpPath); 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = &tmpPath; 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 962a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 96332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()) { 9648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 96532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, 966045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com &fRC->getBounds(), paint->getMaskFilter(), &mask, 9678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::kComputeBoundsAndRenderImage_CreateMode)) { 96832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com this->drawDevMask(mask, *paint); 9698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::FreeImage(mask.fImage); 9708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // avoid possibly allocating a new path in transform if we can 9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; 9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform the path into device space 9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*matrix, devPathPtr); 9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 98032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint); 9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // how does filterPath() know to fill or hairline the path??? <mrr> 98332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getMaskFilter() && 984045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, 98532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com fBounder, blitter.get())) { 9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // filterPath() called the blitter, so we're done 9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 98932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (fBounder && !fBounder->doPath(*devPathPtr, *paint, doFill)) { 9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 993045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); 9948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 99532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 996045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com proc = SkScan::AntiFillPath; 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 998045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com proc = SkScan::FillPath; 9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 100132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 1002045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com proc = SkScan::AntiHairPath; 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 1004045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com proc = SkScan::HairPath; 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1007045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com proc(*devPathPtr, *fRC, blitter.get()); 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10100baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com/** For the purposes of drawing bitmaps, if a matrix is "almost" translate 10110baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com go ahead and treat it as if it were, so that subsequent code can go fast. 10120baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com */ 10130baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.comstatic bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { 10140baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkMatrix::TypeMask mask = matrix.getType(); 10150baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com 10160baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 10170baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return false; 10180baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 10190baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & SkMatrix::kScale_Mask) { 10200baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sx = matrix[SkMatrix::kMScaleX]; 10210baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sy = matrix[SkMatrix::kMScaleY]; 10220baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int w = bitmap.width(); 10230baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int h = bitmap.height(); 10240baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w))); 10250baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h))); 10260baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return sw == w && sh == h; 10270baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 10280baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com // if we got here, we're either kTranslate_Mask or identity 10290baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return true; 10308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, 10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap.getConfig() == SkBitmap::kA8_Config); 10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1036a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com if (just_translate(*fMatrix, bitmap)) { 10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(fMatrix->getTranslateX()); 10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(fMatrix->getTranslateY()); 10398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 10418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = bitmap.rowBytes(); 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = bitmap.getAddr8(0, 0); 1045a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // need to xform the bitmap first 10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 1050a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, 10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); 10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapRect(&r); 10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.round(&mask.fBounds); 1055a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // set the mask's bounds to the transformed bitmap-bounds, 10578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // clipped to the actual device 10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devBounds; 10608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); 10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need intersect(l, t, r, b) on irect 10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!mask.fBounds.intersect(devBounds)) { 10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1066543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com 10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = SkAlign4(mask.fBounds.width()); 1069543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask.computeImageSize(); 1070543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 1071543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // the mask is too big to allocated, draw nothing 1072543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return; 1073543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // allocate (and clear) our temp buffer to hold the transformed bitmap 10768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMalloc storage(size); 10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)storage.get(); 10788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask.fImage, 0, size); 1079a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now draw our bitmap(src) into mask(dst), transformed by the matrix 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap device; 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), 10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.height(), mask.fRowBytes); 10858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setPixels(mask.fImage); 1086a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas c(device); 10888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need the unclipped top/left for the translate 10898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.translate(-SkIntToScalar(mask.fBounds.fLeft), 10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 10918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.concat(*fMatrix); 10923469c76c40790b409621fd7eff34f56240718549reed@android.com 10933469c76c40790b409621fd7eff34f56240718549reed@android.com // We can't call drawBitmap, or we'll infinitely recurse. Instead 1094fb12c3e6ba84f95dc15fbaddc239dede0ba1d60ereed@android.com // we manually build a shader and draw that into our new mask 10953469c76c40790b409621fd7eff34f56240718549reed@android.com SkPaint tmpPaint; 10963469c76c40790b409621fd7eff34f56240718549reed@android.com tmpPaint.setFlags(paint.getFlags()); 109740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, tmpPaint); 10983469c76c40790b409621fd7eff34f56240718549reed@android.com SkRect rr; 10993469c76c40790b409621fd7eff34f56240718549reed@android.com rr.set(0, 0, SkIntToScalar(bitmap.width()), 11003469c76c40790b409621fd7eff34f56240718549reed@android.com SkIntToScalar(bitmap.height())); 110140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com c.drawRect(rr, install.paintWithShader()); 11028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 11048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1107045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comstatic bool clipped_out(const SkMatrix& m, const SkRasterClip& c, 11088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& srcR) { 11098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect dstR; 11108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devIR; 1111a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.mapRect(&dstR, srcR); 1113a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com dstR.roundOut(&devIR); 11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return c.quickReject(devIR); 11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1117045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comstatic bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip, 11188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int width, int height) { 11198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 11208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); 11218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return clipped_out(matrix, clip, r); 11228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1124045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comstatic bool clipHandlesSprite(const SkRasterClip& clip, int x, int y, 1125045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkBitmap& bitmap) { 1126045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return clip.isBW() || 1127045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height()); 1128045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com} 1129045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 113140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1132f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 11338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1135045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty() || 11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 1137dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com bitmap.getConfig() == SkBitmap::kNo_Config) { 11388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1140a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1141a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#ifndef SK_ALLOW_OVER_32K_BITMAPS 11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // run away on too-big bitmaps for now (exceed 16.16) 11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.width() > 32767 || bitmap.height() > 32767) { 11448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1146a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#endif 1147a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 114840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 114940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 1150a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!matrix.setConcat(*fMatrix, prematrix)) { 11538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1156045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1160218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (fBounder && just_translate(matrix, bitmap)) { 1161218521e15706c4377b1be49d931c4d7c8d597445reed@android.com SkIRect ir; 1162218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t ix = SkScalarRound(matrix.getTranslateX()); 1163218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t iy = SkScalarRound(matrix.getTranslateY()); 1164218521e15706c4377b1be49d931c4d7c8d597445reed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1165218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (!fBounder->doIRect(ir)) { 1166218521e15706c4377b1be49d931c4d7c8d597445reed@android.com return; 1167218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1168218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1169218521e15706c4377b1be49d931c4d7c8d597445reed@android.com 1170218521e15706c4377b1be49d931c4d7c8d597445reed@android.com // only lock the pixels if we passed the clip and bounder tests 11718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoLockPixels alp(bitmap); 11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // after the lock, check if we are valid 11738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!bitmap.readyToDraw()) { 11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11770baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (bitmap.getConfig() != SkBitmap::kA8_Config && 11780baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com just_translate(matrix, bitmap)) { 1179045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com int ix = SkScalarRound(matrix.getTranslateX()); 1180045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com int iy = SkScalarRound(matrix.getTranslateY()); 1181045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (clipHandlesSprite(*fRC, ix, iy, bitmap)) { 1182045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com uint32_t storage[kBlitterStorageLongCount]; 1183045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 1184045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com ix, iy, storage, sizeof(storage)); 1185045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (blitter) { 1186045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 1187045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 1188045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkIRect ir; 1189045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1190045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 1191045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::FillIRect(ir, *fRC, blitter); 1192045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return; 11938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1196a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now make a temp draw on the stack, and use it 11988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // 11998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 12008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 1201a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.getConfig() == SkBitmap::kA8_Config) { 12038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawBitmapAsMask(bitmap, paint); 12048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 120540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 12088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(bitmap.width()), 12098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.height())); 1210a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this ok if paint has a rasterizer? 121140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, install.paintWithShader()); 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 121640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1217f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 1218a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1220045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isEmpty() || 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 1222dcd0f3a980095b77ebe605b49777a4bd37ca7b0areed@google.com bitmap.getConfig() == SkBitmap::kNo_Config) { 12238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect bounds; 12278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); 12288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1229045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->quickReject(bounds)) { 12308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // nothing to draw 12318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 123340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 123440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 12358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1236045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, bitmap)) { 12378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x, y, storage, sizeof(storage)); 12408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 12428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(bounds)) { 12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1248045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::FillIRect(bounds, *fRC, blitter); 12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 125340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 125440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& shaderPaint = install.paintWithShader(); 12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 12588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // get a scalar version of our rect 12608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(bounds); 12618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // tell the shader our offset 12638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(r.fLeft, r.fTop); 126440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com shaderPaint.getShader()->setLocalMatrix(matrix); 1265a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 12678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.reset(); 12688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 12698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // call ourself with a rect 1270a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this OK if paint has a rasterizer? 127140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, shaderPaint); 12728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 12758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalerContext.h" 12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGlyphCache.h" 12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, 12818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char text[], size_t byteLength, SkVector* stopVector) { 12828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = 0, y = 0; 12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 1286a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // don't need x, y here, since all subpixel variants will have the 12898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // same advance 12908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 12918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += autokern.adjust(glyph) + glyph.fAdvanceX; 12938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y += glyph.fAdvanceY; 12948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); 12968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(text == stop); 12988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText_asPaths(const char text[], size_t byteLength, 13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, 13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 1303f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 13088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setScale(iter.getPathScale(), iter.getPathScale()); 13098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(x, y); 13108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 13128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos, prevXPos = 0; 13138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 13158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(xpos - prevXPos, 0); 1316f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPaint& pnt = iter.getPaint(); 1317f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1318f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, *iterPath, pnt, &matrix, false); 1319f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1320f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(*iterPath, pnt, &matrix, false); 1321f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 13228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com prevXPos = xpos; 13238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// disable warning : local variable used without having been initialized 1327a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#if defined _WIN32 && _MSC_VER >= 1300 13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( push ) 13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( disable : 4701 ) 13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 13318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 13338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RectClip(const SkDraw1Glyph& state, 1335f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1336f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1337f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1338f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 134083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkASSERT(NULL == state.fBounder); 134183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkASSERT((NULL == state.fClip && state.fAAClip) || 134283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com (state.fClip && NULL == state.fAAClip && state.fClip->isRect())); 13438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int right = left + glyph.fWidth; 13488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int bottom = top + glyph.fHeight; 13498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 135083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkMask mask; 135183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkIRect storage; 135283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkIRect* bounds = &mask.fBounds; 135383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com 135483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fBounds.set(left, top, right, bottom); 135583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com 135683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com // this extra test is worth it, assuming that most of the time it succeeds 135783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com // since we can avoid writing to storage 135883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { 135983a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) 136083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com return; 136183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com bounds = &storage; 136283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 136383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com 136483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com uint8_t* aa = (uint8_t*)glyph.fImage; 136583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 136683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com aa = (uint8_t*)state.fCache->findImage(glyph); 136783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 136883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com return; // can't rasterize glyph 13698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 137083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 13718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 137283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fRowBytes = glyph.rowBytes(); 137383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 137483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fImage = aa; 137583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com state.fBlitter->blitMask(mask, *bounds); 13768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, 1379f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 138083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const SkGlyph& glyph) { 1381f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1382f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 138483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkASSERT(!state.fClip->isRect()); 138583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkASSERT(NULL == state.fBounder); 13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 139383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 139483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com 139583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (!clipper.done()) { 139683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const SkIRect& cr = clipper.rect(); 139783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 139883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 139983a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com aa = (uint8_t*)state.fCache->findImage(glyph); 140083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 140183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com return; 14028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 140383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 140483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com 140583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fRowBytes = glyph.rowBytes(); 140683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 140783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fImage = (uint8_t*)aa; 140883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com do { 140983a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com state.fBlitter->blitMask(mask, cr); 141083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com clipper.next(); 141183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } while (!clipper.done()); 141283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 14138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_Bounder(const SkDraw1Glyph& state, 1416f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 141783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const SkGlyph& glyph) { 1418f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1419f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 14208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 1421045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 14228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 1423045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 1426045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 1429045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 143083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (!clipper.done()) { 143183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const SkIRect& cr = clipper.rect(); 143283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 143383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 143483a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com aa = (uint8_t*)state.fCache->findImage(glyph); 143583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (NULL == aa) { 143683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com return; 14378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 143883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 1439045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 1440d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // we need to pass the origin, which we approximate with our 1441d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // (unadjusted) left,top coordinates (the caller called fixedfloor) 144283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com if (state.fBounder->doIRectGlyph(cr, 1443d055c1fde2128514167b315f4d104b177e04a3dereed@android.com left - glyph.fLeft, 1444d055c1fde2128514167b315f4d104b177e04a3dereed@android.com top - glyph.fTop, glyph)) { 144583a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fRowBytes = glyph.rowBytes(); 144683a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 144783a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com mask.fImage = (uint8_t*)aa; 144883a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com do { 144983a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com state.fBlitter->blitMask(mask, cr); 145083a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com clipper.next(); 145183a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } while (!clipper.done()); 145283a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 145383a444602ec580a0040713eed588c245b4ae0ee9tomhudson@google.com } 14548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1456045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comstatic void D1G_Bounder_AAClip(const SkDraw1Glyph& state, 1457045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkFixed fx, SkFixed fy, 1458045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkGlyph& glyph) { 1459045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com int left = SkFixedFloor(fx); 1460045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com int top = SkFixedFloor(fy); 1461045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkIRect bounds; 1462045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com bounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 1463045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 1464045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (state.fBounder->doIRectGlyph(bounds, left, top, glyph)) { 1465045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com D1G_NoBounder_RectClip(state, fx, fy, glyph); 1466045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 1467045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com} 1468045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 1469fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool hasCustomD1GProc(const SkDraw& draw) { 1470fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return draw.fProcs && draw.fProcs->fD1GProc; 1471fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1472fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 1473fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool needsRasterTextBlit(const SkDraw& draw) { 1474fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return !hasCustomD1GProc(draw); 1475fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1476fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 14778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, 14788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache) { 14798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDraw = draw; 14808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBounder = draw->fBounder; 14818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = blitter; 14828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCache = cache; 14838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14841d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*draw)) { 1485045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com // todo: fix this assumption about clips w/ custom 1486045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = draw->fClip; 1487045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClipBounds = fClip->getBounds(); 14888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw->fProcs->fD1GProc; 14898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1491045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (draw->fRC->isBW()) { 1492045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fAAClip = NULL; 1493045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = &draw->fRC->bwRgn(); 1494045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClipBounds = fClip->getBounds(); 1495045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (NULL == fBounder) { 1496045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fClip->isRect()) { 1497045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return D1G_NoBounder_RectClip; 1498045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } else { 1499045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return D1G_NoBounder_RgnClip; 1500045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 1501045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } else { 1502045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return D1G_Bounder; 1503045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 1504045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } else { // aaclip 1505045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fAAClip = &draw->fRC->aaRgn(); 1506045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClip = NULL; 1507045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com fClipBounds = fAAClip->getBounds(); 1508045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (NULL == fBounder) { 15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RectClip; 15108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 1511045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com return D1G_Bounder_AAClip; 15128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 15178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText(const char text[], size_t byteLength, 15198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, const SkPaint& paint) const { 15208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 15218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1522f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 15238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1525045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (text == NULL || byteLength == 0 || fRC->isEmpty()) { 15268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 15278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 15308d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 15318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawText_asPaths(text, byteLength, x, y, paint); 15328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 15338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 15368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1537f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 15381d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1539f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1540f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1541f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1542f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1543f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1544f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1545f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1546f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 15478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1548a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform our starting point 15508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 15518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint loc; 1552f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix->mapXY(x, y, &loc); 15538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x = loc.fX; 15548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y = loc.fY; 15558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 15588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector stop; 15608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com measure_text(cache, glyphCacheProc, text, byteLength, &stop); 15628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopX = stop.fX; 15648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopY = stop.fY; 15658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 15678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopX = SkScalarHalf(stopX); 15688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopY = SkScalarHalf(stopY); 15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x -= stopX; 15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y -= stopY; 15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1573a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(x); 15758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(y); 15768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 15778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1578f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1579f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 15808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 1581cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*matrix); 1582cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == baseline) { 1583f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1584cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == baseline) { 1585f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 15868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1588f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // apply the bias here, so we don't have to add 1/2 in the loop 1589f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx += SK_FixedHalf; 1590f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fy += SK_FixedHalf; 15918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1592045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAAClipBlitter aaBlitter; 1593045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAutoBlitterChoose blitterChooser; 1594045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBlitter* blitter = NULL; 15951d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 1596045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitterChooser.choose(*fBitmap, *matrix, paint); 1597045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = blitterChooser.get(); 1598045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isAA()) { 1599045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com aaBlitter.init(blitter, &fRC->aaRgn()); 1600045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = &aaBlitter; 1601045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 16021d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 16031d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 16048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 160552c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com SkDraw1Glyph d1g; 1606045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache); 16078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1609f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 16108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += autokern.adjust(glyph); 16128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 161452c748b1691f02f90b27c35bc05074fcef709e66bungeman@google.com proc(d1g, fx, fy, glyph); 16158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += glyph.fAdvanceX; 16178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy += glyph.fAdvanceY; 16188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// last parameter is interpreted as SkFixed [x, y] 16228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// return the fixed position, which may be rounded or not by the caller 16238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// e.g. subpixel doesn't round 16248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); 16258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); 16298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), 16348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); 16358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, 16408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - glyph.fAdvanceY); 16418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic AlignProc pick_align_proc(SkPaint::Align align) { 16448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const AlignProc gProcs[] = { 16458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com leftAlignProc, centerAlignProc, rightAlignProc 16468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1647a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); 16498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return gProcs[align]; 16518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass TextMapState { 16548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 16558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPoint fLoc; 1656a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState(const SkMatrix& matrix, SkScalar y) 16588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} 16598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); 1661a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc pickProc(int scalarsPerPosition); 1663a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 16658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& fMatrix; 16668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc fProc; 16678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fY; // ignored by MapXYProc 16688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // these are only used by Only... procs 16698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fScaleX, fTransX, fTransformedY; 16708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXProc(const TextMapState& state, const SkScalar pos[]) { 16728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc); 16738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1674a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXYProc(const TextMapState& state, const SkScalar pos[]) { 16768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc); 16778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1678a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyScaleXProc(const TextMapState& state, 16808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX, 16828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fTransformedY); 16838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1684a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyTransXProc(const TextMapState& state, 16868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(*pos + state.fTransX, state.fTransformedY); 16888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 16908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comTextMapState::Proc TextMapState::pickProc(int scalarsPerPosition) { 16928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1693a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (1 == scalarsPerPosition) { 16958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned mtype = fMatrix.getType(); 16968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 16978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXProc; 16988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 16998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fScaleX = fMatrix.getScaleX(); 17008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransX = fMatrix.getTranslateX(); 17018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) + 17028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix.getTranslateY(); 17038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (mtype & SkMatrix::kScale_Mask) ? 17048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MapOnlyScaleXProc : MapOnlyTransXProc; 17058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXYProc; 17088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 17108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 17128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPosText(const char text[], size_t byteLength, 17148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[], SkScalar constY, 17158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scalarsPerPosition, const SkPaint& paint) const { 17168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 17178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 17188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1719f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 17208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1722045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (text == NULL || byteLength == 0 || fRC->isEmpty()) { 17238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 17248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 17278d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 17288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // TODO !!!! 17298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// this->drawText_asPaths(text, byteLength, x, y, paint); 17308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 17318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1733f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 17341d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1735f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1736f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1737f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1738f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1739f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1740f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1741a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1743f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 17448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1745a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1746045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAAClipBlitterWrapper wrapper; 1747045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkAutoBlitterChoose blitterChooser; 1748045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBlitter* blitter = NULL; 17491d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 1750045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitterChooser.choose(*fBitmap, *matrix, paint); 1751045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = blitterChooser.get(); 1752045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (fRC->isAA()) { 1753045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com wrapper.init(*fRC, blitter); 1754045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com blitter = wrapper.getBlitter(); 1755045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com } 17561d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 17571d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 17588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 17598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com AlignProc alignProc = pick_align_proc(paint.getTextAlign()); 17608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph d1g; 1761045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache); 1762f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com TextMapState tms(*matrix, constY); 17638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); 17648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 17668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // maybe we should skip the rounding if linearText is set 1767cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com SkAxisAlignment roundBaseline = SkComputeAxisAlignmentForHText(*matrix); 17688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkPaint::kLeft_Align == paint.getTextAlign()) { 17708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1771a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1773a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(tms.fLoc.fX); 17758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(tms.fLoc.fY); 1776f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1777f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1779cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1780f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1781cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1782f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1784a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1785f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 1786f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx & fxMask, fy & fyMask); 1787a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 1789f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, glyph); 17908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph* glyph = &glyphCacheProc(cache, &text, 0, 0); 1796a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph->fWidth) { 17988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvX = glyph->fAdvanceX;) 17998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvY = glyph->fAdvanceY;) 18008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx, fy; 1802f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1803f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 18048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1805a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 18078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 18088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, *glyph, &fixedLoc); 18098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx = fixedLoc.fX; 18108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy = fixedLoc.fY; 18118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1812cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com if (kX_SkAxisAlignment == roundBaseline) { 1813f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1814cb6ccdde5120ec45df208c0b958b263d8252a505reed@google.com } else if (kY_SkAxisAlignment == roundBaseline) { 1815f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 18168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1818a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // have to call again, now that we've been "aligned" 1820f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com glyph = &glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 18218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the assumption is that the advance hasn't changed 18228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvX == glyph->fAdvanceX); 18238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvY == glyph->fAdvanceY); 1824a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1825f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, *glyph); 18268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 18288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // not subpixel 18318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 18328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the last 2 parameters are ignored 18338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1834a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 18368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1837a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 18398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, glyph, &fixedLoc); 1840a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1841f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fixedLoc.fX + SK_FixedHalf, 1842f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fixedLoc.fY + SK_FixedHalf, glyph); 18438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 18458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined _WIN32 && _MSC_VER >= 1300 18508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( pop ) 18518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 18528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 18548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathMeasure.h" 18568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpoints(SkPoint dst[], const SkPoint src[], int count, 18588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure& meas, const SkMatrix& matrix) { 18598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc proc = matrix.getMapXYProc(); 18608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 18628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pos; 18638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector tangent; 18648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(matrix, src[i].fX, src[i].fY, &pos); 18668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = pos.fX; 18678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = pos.fY; 18688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com meas.getPosTan(sx, &pos, &tangent); 18708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* This is the old way (that explains our approach but is way too slow 18728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 18738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pt; 18748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pt.set(sx, sy); 18768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setSinCos(tangent.fY, tangent.fX); 18778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.preTranslate(-sx, 0); 18788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(pos.fX, pos.fY); 18798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapPoints(&dst[i], &pt, 1); 18808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 18818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy), 18828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos.fY + SkScalarMul(tangent.fX, sy)); 18838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* TODO 18878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Need differentially more subdivisions when the follow-path is curvy. Not sure how to 18898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com determine that, but we need it. I guess a cheap answer is let the caller tell us, 18908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out. 18918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 18928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, 18938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix) { 18948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Iter iter(src, false); 18958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint srcP[4], dstP[3]; 18968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Verb verb; 18978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { 18998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (verb) { 19008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kMove_Verb: 19018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 1, meas, matrix); 19028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->moveTo(dstP[0]); 19038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kLine_Verb: 19058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // turn lines into quads to look bendy 19068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX); 19078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY); 19088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 2, meas, matrix); 19098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 19108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kQuad_Verb: 19128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 2, meas, matrix); 19138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 19148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kCubic_Verb: 19168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 3, meas, matrix); 19178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->cubicTo(dstP[0], dstP[1], dstP[2]); 19188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kClose_Verb: 19208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->close(); 19218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 19238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"unknown verb"); 19248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawTextOnPath(const char text[], size_t byteLength, 19308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& follow, const SkMatrix* matrix, 19318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 19328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 19338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 1935045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (text == NULL || byteLength == 0 || fRC->isEmpty()) { 19368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 19378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 19408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure meas(follow, false); 19418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar hOffset = 0; 19428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 19448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 19458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar pathLen = meas.getLength(); 19468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 19478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathLen = SkScalarHalf(pathLen); 19488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hOffset += pathLen; 19508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 19538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos; 19548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix scaledMatrix; 19558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar scale = iter.getPathScale(); 19568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scaledMatrix.setScale(scale, scale); 1958a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 19598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 19608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 19618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m(scaledMatrix); 19628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postTranslate(xpos + hOffset, 0); 19648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (matrix) { 19658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postConcat(*matrix); 19668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpath(&tmp, *iterPath, meas, m); 1968f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1969f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); 1970f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1971f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(tmp, iter.getPaint(), NULL, true); 1972f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 19738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1976cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#ifdef ANDROID 1977cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.comvoid SkDraw::drawPosTextOnPath(const char text[], size_t byteLength, 1978cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPoint pos[], const SkPaint& paint, 1979cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath& path, const SkMatrix* matrix) const { 1980cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // nothing to draw 1981045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (text == NULL || byteLength == 0 || fRC->isEmpty()) { 1982cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return; 1983cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1984cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1985cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix scaledMatrix; 1986cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPathMeasure meas(path, false); 1987cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1988cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc( 1989cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint::kForward_TextBufferDirection, true); 1990cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1991cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Copied (modified) from SkTextToPathIter constructor to setup paint 1992cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint tempPaint(paint); 1993cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1994cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setLinearText(true); 1995cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup 1996cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1997cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (tempPaint.getPathEffect() == NULL && !(tempPaint.getStrokeWidth() > 0 1998cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com && tempPaint.getStyle() != SkPaint::kFill_Style)) { 1999cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setStyle(SkPaint::kFill_Style); 2000cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setPathEffect(NULL); 2001cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2002cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // End copied from SkTextToPathIter constructor 2003cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2004cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // detach cache 2005cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache* cache = tempPaint.detachCache(NULL); 2006cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2007cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Must set scale, even if 1 2008cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkScalar scale = SK_Scalar1; 2009cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com scaledMatrix.setScale(scale, scale); 2010cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2011cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Loop over all glyph ids 2012cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for (const char* stop = text + byteLength; text < stop; pos++) { 2013cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2014cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkGlyph& glyph = glyphCacheProc(cache, &text); 2015cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPath tmp; 2016cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2017cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath* glyphPath = cache->findPath(glyph); 2018cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (glyphPath == NULL) { 2019cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com continue; 2020cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2021cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2022cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix m(scaledMatrix); 2023cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postTranslate(pos->fX, 0); 2024cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2025cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (matrix) { 2026cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postConcat(*matrix); 2027cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2028cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2029cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com morphpath(&tmp, *glyphPath, meas, m); 2030cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com this->drawPath(tmp, tempPaint); 2031cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2032cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2033cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2034cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // re-attach cache 2035cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache::AttachCache(cache); 2036cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com} 2037cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif 2038cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 20398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 20408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct VertState { 20428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int f0, f1, f2; 20438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState(int vCount, const uint16_t indices[], int indexCount) 20458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fIndices(indices) { 20468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCurrIndex = 0; 20478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (indices) { 20488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = indexCount; 20498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = vCount; 20518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2053a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2054a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com typedef bool (*Proc)(VertState*); 20558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkCanvas::VertexMode mode); 20568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 20588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCount; 20598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCurrIndex; 20608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* fIndices; 2061a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 20628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool Triangles(VertState*); 20638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TrianglesX(VertState*); 20648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStrip(VertState*); 20658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStripX(VertState*); 20668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFan(VertState*); 20678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFanX(VertState*); 20688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 20698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::Triangles(VertState* state) { 20718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TrianglesX(VertState* state) { 20838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStrip(VertState* state) { 20968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 21018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 21028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 1; 21038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 0; 21048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 21068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 21078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStripX(VertState* state) { 21138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 21148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 21198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 21208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 1]; 21218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 0]; 21228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 21248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 21258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFan(VertState* state) { 21318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = 0; 21368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 21378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 21388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFanX(VertState* state) { 21438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 21448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[0]; 21498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 21508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 21518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comVertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { 21568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 21578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangles_VertexMode: 21588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TrianglesX : Triangles; 21598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleStrip_VertexMode: 21608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleStripX : TriangleStrip; 21618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleFan_VertexMode: 21628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleFanX : TriangleFan; 21638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 21648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 21658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2168045e62d715f5ee9b03deb5af3c750f8318096179reed@google.comtypedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, 21698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 21708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic HairProc ChooseHairProc(bool doAntiAlias) { 21728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; 21738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool texture_to_matrix(const VertState& state, const SkPoint verts[], 21768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint texs[], SkMatrix* matrix) { 21778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src[3], dst[3]; 2178a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[0] = texs[state.f0]; 21808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[1] = texs[state.f1]; 21818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[2] = texs[state.f2]; 21828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[0] = verts[state.f0]; 21838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[1] = verts[state.f1]; 21848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[2] = verts[state.f2]; 21858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return matrix->setPolyToPoly(src, dst, 3); 21868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkTriColorShader : public SkShader { 21898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 21908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader() {} 21918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); 2193a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count); 2195a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 21978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader(SkFlattenableReadBuffer& buffer) : SkShader(buffer) {} 2198a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 2200a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 22028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix fDstToUnit; 22038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor fColors[3]; 2204a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 22068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkTriColorShader, (buffer)); 22078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkShader INHERITED; 22098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 22108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkTriColorShader::setup(const SkPoint pts[], const SkColor colors[], 22128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index0, int index1, int index2) { 2213a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[0] = SkPreMultiplyColor(colors[index0]); 22158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[1] = SkPreMultiplyColor(colors[index1]); 22168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[2] = SkPreMultiplyColor(colors[index2]); 2217a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m, im; 22198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 22208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(0, pts[index1].fX - pts[index0].fX); 22218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(1, pts[index2].fX - pts[index0].fX); 22228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(2, pts[index0].fX); 22238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(3, pts[index1].fY - pts[index0].fY); 22248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(4, pts[index2].fY - pts[index0].fY); 22258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(5, pts[index0].fY); 22268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!m.invert(&im)) { 22278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 22288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fDstToUnit.setConcat(im, this->getTotalInverse()); 22308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 2233689411a87ca7d19abe04b5c9baff26bd96b2123ereed@android.com#include "SkComposeShader.h" 22348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic int ScalarTo256(SkScalar v) { 22368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale = SkScalarToFixed(v) >> 8; 22378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale < 0) { 22388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 0; 22398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale > 255) { 22418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 255; 22428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkAlpha255To256(scale); 22448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkTriColorShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { 22478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src; 2248a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 22508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 22518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += 1; 2252a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale1 = ScalarTo256(src.fX); 22548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale2 = ScalarTo256(src.fY); 22558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale0 = 256 - scale1 - scale2; 22568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale0 < 0) { 22578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale1 > scale2) { 22588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale2 = 256 - scale1; 22598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 22608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale1 = 256 - scale2; 22618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale0 = 0; 22638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2264a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 22668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[1], scale1) + 22678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[2], scale2); 22688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, 22728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint textures[], 22738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 22748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 22758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 22768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == count || NULL != vertices); 2277a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // abort early if there is nothing to draw 2279045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) { 22808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2282a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform out vertices into device coordinates 22848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoSTMalloc<16, SkPoint> storage(count); 22858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint* devVerts = storage.get(); 22868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapPoints(devVerts, vertices, count); 2287a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder) { 22898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 22908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(devVerts, count); 22918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!fBounder->doRect(bounds, paint)) { 22928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2295a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 22978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com We can draw the vertices in 1 of 4 ways: 22988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - solid color (no shader/texture[], no colors[]) 23008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just colors (no shader/texture[], has colors[]) 23018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just texture (has shader/texture[], no colors[]) 23028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - colors * texture (has shader/texture[], has colors[]) 2303a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Thus for texture drawing, we need both texture[] and a shader. 23058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 23068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader triShader; // must be above declaration of p 23088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 23098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* shader = p.getShader(); 23118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == shader) { 23128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we have no shader, we ignore the texture coordinates 23138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textures = NULL; 23148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (NULL == textures) { 23158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we don't have texture coordinates, ignore the shader 23168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(NULL); 23178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader = NULL; 23188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup the custom shader (if needed) 23218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == textures) { 23238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // just colors (no texture) 23248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(&triShader); 23258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // colors * texture 23278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(shader); 23288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool releaseMode = false; 23298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == xmode) { 2330845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com xmode = SkXfermode::Create(SkXfermode::kMultiply_Mode); 23318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com releaseMode = true; 23328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* compose = SkNEW_ARGS(SkComposeShader, 23348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (&triShader, shader, xmode)); 23358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(compose)->unref(); 23368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (releaseMode) { 23378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xmode->unref(); 23388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); 23438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup our state and function pointer for iterating triangles 23448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState state(count, indices, indexCount); 23458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState::Proc vertProc = state.chooseProc(vmode); 2346a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures || NULL != colors) { 23488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix localM, tempM; 23498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasLocalM = shader && shader->getLocalMatrix(&localM); 2350a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setContext(*fBitmap, p, *fMatrix)) { 23538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colors = NULL; 23548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2356a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 23588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures) { 23598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (texture_to_matrix(state, vertices, textures, &tempM)) { 23608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tempM.postConcat(localM); 23628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(tempM); 23648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to recal setContext since we changed the local matrix 23658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!shader->setContext(*fBitmap, p, *fMatrix)) { 23668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setup(vertices, colors, 23728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.f0, state.f1, state.f2)) { 23738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2376045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com 2377045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkPoint tmp[] = { 2378045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] 2379045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com }; 2380045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkScan::FillTriangle(tmp, *fRC, blitter.get()); 23818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now restore the shader's original local matrix 23838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != shader) { 23848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(localM); 23868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->resetLocalMatrix(); 23888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // no colors[] and no texture 23928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); 2393045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkRasterClip& clip = *fRC; 23948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 2395045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()); 2396045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()); 2397045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()); 23988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24020a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24030a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 24068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2407f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkDraw::validate() const { 24088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fBitmap != NULL); 24098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fMatrix != NULL); 24108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fClip != NULL); 2411045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkASSERT(fRC != NULL); 24128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2413045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com const SkIRect& cr = fRC->getBounds(); 24148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect br; 24158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2416f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com br.set(0, 0, fBitmap->width(), fBitmap->height()); 24178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(cr.isEmpty() || br.contains(cr)); 2418f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 2419f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // assert that both are null, or both are not-null 2420f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkASSERT(!fMVMatrix == !fExtMatrix); 24218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 24248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24250a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24260a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com 24270a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.comSkBounder::SkBounder() { 24280a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com // initialize up front. This gets reset by SkCanvas before each draw call. 24290a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com fClip = &SkRegion::GetEmptyRegion(); 24300a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com} 24318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doIRect(const SkIRect& r) { 24338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect rr; 24348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return rr.intersect(fClip->getBounds(), r) && this->onIRect(rr); 24358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2437d055c1fde2128514167b315f4d104b177e04a3dereed@android.com// TODO: change the prototype to take fixed, and update the callers 2438d055c1fde2128514167b315f4d104b177e04a3dereed@android.combool SkBounder::doIRectGlyph(const SkIRect& r, int x, int y, 2439d055c1fde2128514167b315f4d104b177e04a3dereed@android.com const SkGlyph& glyph) { 2440474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com SkIRect rr; 2441d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (!rr.intersect(fClip->getBounds(), r)) { 2442d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return false; 2443d055c1fde2128514167b315f4d104b177e04a3dereed@android.com } 2444d055c1fde2128514167b315f4d104b177e04a3dereed@android.com GlyphRec rec; 2445d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.set(SkIntToFixed(x), SkIntToFixed(y)); 2446d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fRSB.set(rec.fLSB.fX + glyph.fAdvanceX, 2447d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.fY + glyph.fAdvanceY); 2448d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fGlyphID = glyph.getGlyphID(); 2449d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fFlags = 0; 2450d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return this->onIRectGlyph(rr, rec); 2451474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com} 2452474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com 24538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doHairline(const SkPoint& pt0, const SkPoint& pt1, 24548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 24558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar v0, v1; 24578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fX; 24598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fX; 24608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 24618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 24628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = SkScalarFloor(v0); 24648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = SkScalarCeil(v1); 24658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fY; 24678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fY; 24688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 24698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 24708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = SkScalarFloor(v0); 24728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = SkScalarCeil(v1); 24738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doRect(const SkRect& rect, const SkPaint& paint) { 24818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getStyle() == SkPaint::kFill_Style) { 24848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.round(&r); 24858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 24868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rad = -1; 24878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.roundOut(&r); 24888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rad = -2; 24908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(rad, rad); 24928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doPath(const SkPath& path, const SkPaint& paint, bool doFill) { 2497d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkIRect r; 2498d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& bounds = path.getBounds(); 24998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 25018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.round(&r); 25028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 25038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&r); 25048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 25078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 25088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 25108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkBounder::commit() { 25138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override in subclass 25148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////////////////////// 25178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 25198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 25208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 25218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 25228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, 25248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 25258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds) { 25268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (devPath.isEmpty()) { 25278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // init our bounds from the path 25318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2532d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkRect pathBounds = devPath.getBounds(); 25338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); 25348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.roundOut(bounds); 25358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2536a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25375af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIPoint margin; 25388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (filter) { 25398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(filterMatrix); 2540a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25415af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkMask srcM, dstM; 2542a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fBounds = *bounds; 25448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fFormat = SkMask::kA8_Format; 25458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fImage = NULL; 25468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { 25478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2550a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25515af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com // (possibly) trim the bounds to reflect the clip 25528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (plus whatever slop the filter needs) 25535af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (clipBounds) { 25545af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com SkIRect tmp = *clipBounds; 25553555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // Ugh. Guard against gigantic margins from wacky filters. Without this 25563555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // check we can request arbitrary amounts of slop beyond our visible 25573555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // clip, and bring down the renderer (at least on finite RAM machines 25583555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // like handsets, etc.). Need to balance this invented value between 25593555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // quality of large filters like blurs, and the corresponding memory 25603555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // requests. 25613555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com static const int MAX_MARGIN = 128; 25623555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), 25633555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com -SkMin32(margin.fY, MAX_MARGIN)); 25645af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com if (!bounds->intersect(tmp)) { 25655af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com return false; 25665af16f8d670b3ce1c7644a4737e02e2e2257614ebungeman@google.com } 25678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 25708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void draw_into_mask(const SkMask& mask, const SkPath& devPath) { 2573045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkBitmap bm; 2574045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkDraw draw; 2575045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkRasterClip clip; 2576045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkMatrix matrix; 2577045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com SkPaint paint; 25788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height(), mask.fRowBytes); 25808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setPixels(mask.fImage); 25818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2582045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com clip.setRect(SkIRect::MakeWH(mask.fBounds.width(), mask.fBounds.height())); 25838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), 25848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 25858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBitmap = &bm; 2587045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com draw.fRC = &clip; 2588045e62d715f5ee9b03deb5af3c750f8318096179reed@google.com draw.fClip = &clip.bwRgn(); 25898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 25908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBounder = NULL; 25918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.setAntiAlias(true); 25928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawPath(devPath, paint); 25938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 25968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 25978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask* mask, SkMask::CreateMode mode) { 25988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustRenderImage_CreateMode != mode) { 25998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds)) 26008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 26018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2602a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 26038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { 26048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fFormat = SkMask::kA8_Format; 26058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fRowBytes = mask->fBounds.width(); 2606543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask->computeImageSize(); 2607543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 2608543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // we're too big to allocate the mask, abort 2609543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return false; 2610543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 2611543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com mask->fImage = SkMask::AllocImage(size); 26128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask->fImage, 0, mask->computeImageSize()); 26138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 26148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 26158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustComputeBounds_CreateMode != mode) { 26168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_into_mask(*mask, devPath); 26178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2618a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 26198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 26208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2621