SkDraw.cpp revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBounder.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDevice.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMaskFilter.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPaint.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h" 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRasterizer.h" 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScan.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStroke.h" 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTemplatesPriv.h" 2428be72b63e457c680c192a34fb9f58e1c693363fvandebo@chromium.org#include "SkTextFormatParams.h" 2532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com#include "SkTLazy.h" 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 27026dceead9b957e0b080d55c5a7fbb919e6f00b6reed@google.com#include <new> 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAutoKern.h" 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmapProcShader.h" 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawProcs.h" 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//#define TRACE_BITMAP_DRAWS 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define kBlitterStorageLongCount (sizeof(SkBitmapProcShader) >> 2) 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 37fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com/** Helper for allocating small blitters on the stack. 38fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com */ 3940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBlitterChoose : SkNoncopyable { 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 411d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose() { 421d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = NULL; 431d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = SkBlitter::Choose(device, matrix, paint, 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage)); 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 491d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBlitterChoose(); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* operator->() { return fBlitter; } 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* get() const { return fBlitter; } 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 551d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com void choose(const SkBitmap& device, const SkMatrix& matrix, 561d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com const SkPaint& paint) { 571d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkASSERT(!fBlitter); 581d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fBlitter = SkBlitter::Choose(device, matrix, paint, 591d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com fStorage, sizeof(fStorage)); 601d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 611d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* fBlitter; 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t fStorage[kBlitterStorageLongCount]; 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkAutoBlitterChoose::~SkAutoBlitterChoose() { 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)fBlitter == (void*)fStorage) { 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter->~SkBlitter(); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(fBlitter); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com/** 7640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * Since we are providing the storage for the shader (to avoid the perf cost 7740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * of calling new) we insist that in our destructor we can account for all 7840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com * owners of the shader. 7940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com */ 8040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comclass SkAutoBitmapShaderInstall : SkNoncopyable { 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 8240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint) 8340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com : fPaint(paint) /* makes a copy of the paint */ { 8440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(SkShader::CreateBitmapShader(src, 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fStorage, sizeof(fStorage))); 8740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // we deliberately left the shader with an owner-count of 2 8840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == fPaint.getShader()->getRefCnt()); 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9082065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkAutoBitmapShaderInstall() { 9240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkShader* shader = fPaint.getShader(); 9340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // since we manually destroy shader, we insist that owners == 2 9440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT(2 == shader->getRefCnt()); 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fPaint.setShader(NULL); // unref the shader by 1 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // now destroy to take care of the 2nd owner-count 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((void*)shader == (void*)fStorage) { 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->~SkShader(); 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDELETE(shader); 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10582065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 10640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com // return the new paint that has the shader applied 10740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& paintWithShader() const { return fPaint; } 10882065d667f64e232bcde2ad849756a6096fcbe6freed@google.com 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 11040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint fPaint; // copy of caller's paint (which we then modify) 11140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com uint32_t fStorage[kBlitterStorageLongCount]; 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 116f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comSkDraw::SkDraw() { 117f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com sk_bzero(this, sizeof(*this)); 118f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 119f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw::SkDraw(const SkDraw& src) { 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memcpy(this, &src, sizeof(*this)); 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*BitmapXferProc)(void* pixels, size_t bytes, uint32_t data); 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Clear_BitmapXferProc(void* pixels, size_t bytes, uint32_t) { 1294516f4786f5dda1b86a8f825b9e8e910d9c2363creed@android.com sk_bzero(pixels, bytes); 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D_Dst_BitmapXferProc(void*, size_t, uint32_t data) {} 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D32_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset32((uint32_t*)pixels, data, bytes >> 2); 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D16_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sk_memset16((uint16_t*)pixels, data, bytes >> 1); 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(pixels, data, bytes); 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap, 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t* data) { 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // todo: we can apply colorfilter up front if no shader, so we wouldn't 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to abort this fastpath 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getShader() || paint.getColorFilter()) { 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 155845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com SkXfermode::Mode mode; 156845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (!SkXfermode::IsMode(paint.getXfermode(), &mode)) { 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 159a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkColor color = paint.getColor(); 161a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // collaps modes based on color... 163845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com if (SkXfermode::kSrcOver_Mode == mode) { 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned alpha = SkColorGetA(color); 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == alpha) { 166845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kDst_Mode; 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (0xFF == alpha) { 168845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com mode = SkXfermode::kSrc_Mode; 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 171a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 173845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kClear_Mode: 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Clear_BitmapXferProc\n"); 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Clear_BitmapXferProc; // ignore data 176845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kDst_Mode: 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D_Dst_BitmapXferProc\n"); 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D_Dst_BitmapXferProc; // ignore data 179845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com case SkXfermode::kSrc_Mode: { 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 181a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com should I worry about dithering for the lower depths? 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor pmc = SkPreMultiplyColor(color); 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = pmc; 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D32_Src_BitmapXferProc\n"); 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D32_Src_BitmapXferProc; 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel4444(pmc); 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkPixel32ToPixel16(pmc); 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- D16_Src_BitmapXferProc\n"); 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D16_Src_BitmapXferProc; 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (data) { 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *data = SkGetPackedA32(pmc); 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// SkDebugf("--- DA8_Src_BitmapXferProc\n"); 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return DA8_Src_BitmapXferProc; 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com BitmapXferProc proc, uint32_t procData) { 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int shiftPerPixel; 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (bitmap.config()) { 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_8888_Config: 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 2; 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kARGB_4444_Config: 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kRGB_565_Config: 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 1; 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkBitmap::kA8_Config: 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shiftPerPixel = 0; 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"Can't use xferproc on this config"); 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t* pixels = (uint8_t*)bitmap.getPixels(); 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pixels); 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t rowBytes = bitmap.rowBytes(); 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const int widthBytes = rect.width() << shiftPerPixel; 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // skip down to the first scanline and X position 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rect.fTop * rowBytes + (rect.fLeft << shiftPerPixel); 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int scans = rect.height() - 1; scans >= 0; --scans) { 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(pixels, widthBytes, procData); 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pixels += rowBytes; 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPaint(const SkPaint& paint) const { 253f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty()) { 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devRect; 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.set(0, 0, fBitmap->width(), fBitmap->height()); 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(devRect)) { 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 264a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* If we don't have a shader (i.e. we're just a solid color) we may 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be faster to operate directly on the device bitmap, rather than invoking 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a blitter. Esp. true for xfermodes, which require a colorshader to be 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com present, which is just redundant work. Since we're drawing everywhere 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com in the clip, we don't have to worry about antialiasing. 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t procData = 0; // to avoid the warning 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData); 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (proc) { 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (D_Dst_BitmapXferProc == proc) { // nothing to do 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 277a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Iterator iter(*fClip); 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (!iter.done()) { 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData); 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com iter.next(); 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // normal case: use a blitter 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillIRect(devRect, fClip, blitter.get()); 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct PtProcRec { 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas::PointMode fMode; 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint* fPaint; 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* fClip; 296a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // computed values 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fRadius; 299a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const PtProcRec&, const SkPoint devPts[], int count, 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool init(SkCanvas::PointMode, const SkPaint&, const SkMatrix* matrix, 304a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com const SkRegion* clip); 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkBlitter* blitter); 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(rec.fClip->isRect()); 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& r = rec.fClip->getBounds(); 312a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_rect_16_hair_proc(const PtProcRec& rec, 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint devPts[], int count, 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter) { 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(rec.fClip->isRect()); 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& r = rec.fClip->getBounds(); 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap); 330a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint16_t* addr = bitmap->getAddr16(0, 0); 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rb = bitmap->rowBytes(); 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (r.contains(x, y)) { 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// *bitmap->getAddr16(x, y) = SkToU16(value); 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ((uint16_t*)((char*)addr + y * rb))[x] = SkToU16(value); 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int x = SkScalarFloor(devPts[i].fX); 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int y = SkScalarFloor(devPts[i].fY); 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (rec.fClip->contains(x, y)) { 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitH(x, y, 1); 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// aa versions 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i += 2) { 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count - 1; i++) { 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairLine(devPts[i], devPts[i+1], rec.fClip, blitter); 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// square procs (strokeWidth > 0 but matrix is square-scale (sx == sy) 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[], 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 393a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 399a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillXRect(r, rec.fClip, blitter); 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[], 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count, SkBlitter* blitter) { 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkFixed radius = rec.fRadius; 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = SkScalarToFixed(devPts[i].fX); 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed y = SkScalarToFixed(devPts[i].fY); 410a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkXRect r; 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = x - radius; 4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = y - radius; 4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = x + radius; 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = y + radius; 416a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiFillXRect(r, rec.fClip, blitter); 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 421b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com// If this guy returns true, then chooseProc() must return a valid proc 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint, 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix, const SkRegion* clip) { 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect()) { 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width = paint.getStrokeWidth(); 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == width) { 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = clip; 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SK_Fixed1 >> 1; 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 435b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com if (paint.getStrokeCap() != SkPaint::kRound_Cap && 436b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com matrix->rectStaysRect() && SkCanvas::kPoints_PointMode == mode) { 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = matrix->get(SkMatrix::kMScaleX); 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = matrix->get(SkMatrix::kMScaleY); 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkScalarNearlyZero(sx - sy)) { 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (sx < 0) { 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com sx = -sx; 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMode = mode; 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaint = &paint; 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = clip; 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comPtProcRec::Proc PtProcRec::chooseProc(SkBlitter* blitter) { 455b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com Proc proc = NULL; 456a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // for our arrays 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == SkCanvas::kPoints_PointMode); 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == SkCanvas::kLines_PointMode); 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(2 == SkCanvas::kPolygon_PointMode); 4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)fMode <= (unsigned)SkCanvas::kPolygon_PointMode); 4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // first check for hairlines 4648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (0 == fPaint->getStrokeWidth()) { 4658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const Proc gAAProcs[] = { 4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa_square_proc, aa_line_hair_proc, aa_poly_hair_proc 4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gAAProcs[fMode]; 4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { 4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t value; 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkBitmap* bm = blitter->justAnOpaqueColor(&value); 4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bm && bm->config() == SkBitmap::kRGB_565_Config) { 4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_16_hair_proc; 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_pt_rect_hair_proc; 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static Proc gBWProcs[] = { 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = gBWProcs[fMode]; 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 486b4f404ac4195e5b1f49e49c591bd69f98b246f9breed@android.com } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) { 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(SkCanvas::kPoints_PointMode == fMode); 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fPaint->isAntiAlias()) { 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = aa_square_proc; 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc = bw_square_proc; 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return proc; 4958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool bounder_points(SkBounder* bounder, SkCanvas::PointMode mode, 4988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t count, const SkPoint pts[], 4998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint, const SkMatrix& matrix) { 5008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ibounds; 5018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 5028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar inset = paint.getStrokeWidth(); 5038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(pts, count); 5058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.inset(-inset, -inset); 5068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapRect(&bounds); 5078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&ibounds); 5098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return bounder->doIRect(ibounds); 5108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 5118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// each of these costs 8-bytes of stack space, so don't make it too large 5138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// must be even for lines/polygon to work 5148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define MAX_DEV_PTS 32 5158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count, 517f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPoint pts[], const SkPaint& paint, 518f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com bool forceUseDevice) const { 5198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we're in lines mode, force count to be even 5208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkCanvas::kLines_PointMode == mode) { 5218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count &= ~(size_t)1; 5228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if ((long)count <= 0) { 5258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 527a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(pts != NULL); 529f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 530a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 5328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 5338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 5348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 5358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 537fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (fBounder) { 538fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com if (!bounder_points(fBounder, mode, count, pts, paint, *fMatrix)) { 539fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 540fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 541fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 542fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // clear the bounder and call this again, so we don't invoke the bounder 543fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com // later if we happen to call ourselves for drawRect, drawPath, etc. 544fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com SkDraw noBounder(*this); 545fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.fBounder = NULL; 546fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com noBounder.drawPoints(mode, count, pts, paint, forceUseDevice); 547fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return; 548fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com } 549fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 5508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec rec; 551f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (!forceUseDevice && rec.init(mode, paint, fMatrix, fClip)) { 5528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 5538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint devPts[MAX_DEV_PTS]; 5558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 5568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* bltr = blitter.get(); 5578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PtProcRec::Proc proc = rec.chooseProc(bltr); 5588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we have to back up subsequent passes if we're in polygon mode 5598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const size_t backup = (SkCanvas::kPolygon_PointMode == mode); 560a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 5628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t n = count; 5638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (n > MAX_DEV_PTS) { 5648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com n = MAX_DEV_PTS; 5658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix->mapPoints(devPts, pts, n); 5678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(rec, devPts, n, bltr); 5688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pts += n - backup; 5698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(count >= n); 5708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= n; 5718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count > 0) { 5728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count += backup; 5738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (count != 0); 5758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 5768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 5778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPoints_PointMode: { 5788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // temporarily mark the paint as filling. 57940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint newPaint(paint); 58040c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com newPaint.setStyle(SkPaint::kFill_Style); 5818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 58240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkScalar width = newPaint.getStrokeWidth(); 5838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar radius = SkScalarHalf(width); 584a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 58540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { 5868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 5878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix preMatrix; 588a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.addCircle(0, 0, radius); 5908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 5918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preMatrix.setTranslate(pts[i].fX, pts[i].fY); 5928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // pass true for the last point, since we can modify 5938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // then path then 594f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 59540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawPath(*this, path, newPaint, &preMatrix, 596f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com (count-1) == i); 597f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 59840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawPath(path, newPaint, &preMatrix, 59940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (count-1) == i); 600f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 6038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 604a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i++) { 6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = pts[i].fX - radius; 6078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = pts[i].fY - radius; 6088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = r.fLeft + width; 6098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = r.fTop + width; 610f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 61140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com fDevice->drawRect(*this, r, newPaint); 612f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 61340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com this->drawRect(r, newPaint); 614f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kLines_PointMode: 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kPolygon_PointMode: { 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count -= 1; 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath path; 6238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 6248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStyle(SkPaint::kStroke_Style); 6258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (size_t i = 0; i < count; i += inc) { 6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.moveTo(pts[i]); 6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.lineTo(pts[i+1]); 629f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 630f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, path, p, NULL, true); 631f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 632f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(path, p, NULL, true); 633f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path.rewind(); 6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_lefttop(SkRect* r) { 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (SkPoint*)(void*)r; 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic inline SkPoint* as_rightbottom(SkRect* r) { 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return ((SkPoint*)(void*)r) + 1; 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 650761fb62b0eb174783316d2a8b933fba896ca6355reed@google.comstatic bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, 651761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint* strokeSize) { 652761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com if (SkPaint::kMiter_Join != paint.getStrokeJoin() || 653761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com paint.getStrokeMiter() < SK_ScalarSqrt2) { 654761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return false; 655761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com } 65662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 657761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkASSERT(matrix.rectStaysRect()); 658761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() }; 659761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com matrix.mapVectors(strokeSize, &pt, 1); 6606115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fX = SkScalarAbs(strokeSize->fX); 6616115338c59799b4ef09cda187f23867dea093f6ereed@google.com strokeSize->fY = SkScalarAbs(strokeSize->fY); 662761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com return true; 6637ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org} 6647ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 66562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comSkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, 66662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const SkMatrix& matrix, 66762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint* strokeSize) { 6687ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org RectType rtype; 6697ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org const SkScalar width = paint.getStrokeWidth(); 67062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com const bool zeroWidth = (0 == width); 6717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::Style style = paint.getStyle(); 67262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) { 6747ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org style = SkPaint::kFill_Style; 6757ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 67662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 6778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getPathEffect() || paint.getMaskFilter() || 67862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com paint.getRasterizer() || !matrix.rectStaysRect() || 6797ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkPaint::kStrokeAndFill_Style == style) { 68062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 68162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (SkPaint::kFill_Style == style) { 6827ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kFill_RectType; 6837ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else if (zeroWidth) { 6847ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kHair_RectType; 68562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } else if (easy_rect_join(paint, matrix, strokeSize)) { 6867ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kStroke_RectType; 6877ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 6887ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org rtype = kPath_RectType; 6897ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 69062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return rtype; 69162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com} 69262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 69340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.comstatic SkPoint* rect_points(SkRect& r, int index) { 69440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkASSERT((unsigned)index < 2); 69540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com return &((SkPoint*)(void*)&r)[index]; 69640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com} 69740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com 69862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.comvoid SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const { 69962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkDEBUGCODE(this->validate();) 7007ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org 70162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com // nothing to draw 70262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (fClip->isEmpty() || 70362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 70462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com return; 70562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 70662ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 70762ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com SkPoint strokeSize; 70862ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); 70962ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 71062ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#ifdef SK_DISABLE_FAST_AA_STROKE_RECT 71162ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com if (kStroke_RectType == rtype && paint.isAntiAlias()) { 71262ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com rtype = kPath_RectType; 71362ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com } 71462ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com#endif 71562ab7addb06bbc5b93460eaf2f70a9f8399308d3reed@google.com 7167ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (kPath_RectType == rtype) { 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.addRect(rect); 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmp.setFillType(SkPath::kWinding_FillType); 720187d5595901d1120d9425851e5afdd773f574502reed@android.com this->drawPath(tmp, paint, NULL, true); 7218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix = *fMatrix; 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect devRect; 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform rect into devRect 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fLeft, rect.fTop, rect_points(devRect, 0)); 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapXY(rect.fRight, rect.fBottom, rect_points(devRect, 1)); 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.sort(); 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doRect(devRect, paint)) { 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // look for the quick exit, before we build a blitter 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devRect.roundOut(&ir); 74255e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com if (paint.getStyle() != SkPaint::kFill_Style) { 74355e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com // extra space for hairlines 74455e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com ir.inset(-1, -1); 74555e76b209c9249308a9ba3d75c2472dd55e9d298reed@android.com } 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(ir)) 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitterStorage(*fBitmap, matrix, paint); 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = blitterStorage.get(); 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRegion* clip = fClip; 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 754b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter 755b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // case we are also hairline (if we've gotten to here), which devolves to 756b641c9f20beb36dbf4e8df53a199c84cef3be9b2reed@android.com // effectively just kFill 7577ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org switch (rtype) { 7587ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kFill_RectType: 7597ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7607ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiFillRect(devRect, clip, blitter); 7617ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7627ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::FillRect(devRect, clip, blitter); 7637ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7647ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7657ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kStroke_RectType: 7667ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 767761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::AntiFrameRect(devRect, strokeSize, clip, blitter); 7687ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 769761fb62b0eb174783316d2a8b933fba896ca6355reed@google.com SkScan::FrameRect(devRect, strokeSize, clip, blitter); 7707ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7717ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7727ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org case kHair_RectType: 7737ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org if (paint.isAntiAlias()) { 7747ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::AntiHairRect(devRect, clip, blitter); 7757ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } else { 7767ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkScan::HairRect(devRect, clip, blitter); 7777ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org } 7787ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org break; 7797ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org default: 7807ff678bc1618dc669648198a7bdca8adfb189505mike@reedtribe.org SkASSERT(!"bad rtype"); 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (srcM.fBounds.isEmpty()) { 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask dstM; 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMask* mask = &srcM; 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstM.fImage = NULL; 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMaskImage ami(&dstM, false); 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getMaskFilter() && 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask = &dstM; 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(mask->fBounds)) { 8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 8058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitMaskRegion(*mask, *fClip); 8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 809ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.comstatic SkScalar fast_len(const SkVector& vec) { 810ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar x = SkScalarAbs(vec.fX); 811ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar y = SkScalarAbs(vec.fY); 812ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com if (x < y) { 813ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkTSwap(x, y); 814ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 815ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return x + SkScalarHalf(y); 816ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 817ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 818ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com// our idea is to return true if there is no appreciable skew or non-square scale 819ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com// for that we'll transform (0,1) and (1,0), and check that the resulting dot-prod 820ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com// is nearly one 821ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.comstatic bool map_radius(const SkMatrix& matrix, SkScalar* value) { 8228d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com if (matrix.hasPerspective()) { 823ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 824ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 825ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkVector src[2], dst[2]; 826ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com src[0].set(*value, 0); 827ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com src[1].set(0, *value); 828ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com matrix.mapVectors(dst, src, 2); 829ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len0 = fast_len(dst[0]); 830ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com SkScalar len1 = fast_len(dst[1]); 831652807bbc8c57e5fa9622126b51fd369f5c67935agl@chromium.org if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { 832ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com *value = SkScalarAve(len0, len1); 833ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return true; 834ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com } 835ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com return false; 836ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com} 837ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com 83832e5d97ccf60f859db063ebd6e903c362e625767reed@google.comvoid SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, 8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* prePathMatrix, bool pathIsMutable) const { 840f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 84432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 8458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* pathPtr = (SkPath*)&origSrcPath; 8498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool doFill = true; 8508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmpPath; 8518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix tmpMatrix; 8528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix* matrix = fMatrix; 8538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (prePathMatrix) { 85532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style || 85632e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getRasterizer()) { 8578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* result = pathPtr; 858a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!pathIsMutable) { 8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com result = &tmpPath; 8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathIsMutable = true; 8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*prePathMatrix, result); 8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = result; 8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!tmpMatrix.setConcat(*matrix, *prePathMatrix)) { 8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // overflow 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix = &tmpMatrix; 8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // at this point we're done with prePathMatrix 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) 875a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the device thickness < 1.0, then make it a hairline, and 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com modulate alpha if the thickness is even smaller (e.g. thickness == 0.5 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com should modulate the alpha by 1/2) 88032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com */ 88132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com 88232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com const SkPaint* paint = &origPaint; 88332e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkTLazy<SkPaint> lazyPaint; 884a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 885ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com // can we approximate a thin (but not hairline) stroke with an alpha-modulated 886ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com // hairline? Only if the matrix scales evenly in X and Y, and the device-width is 887ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com // less than a pixel 88832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (origPaint.isAntiAlias() && 88932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getStyle() == SkPaint::kStroke_Style && 89032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com origPaint.getXfermode() == NULL) { 89132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkScalar width = origPaint.getStrokeWidth(); 892ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com if (width > 0 && map_radius(*matrix, &width)) { 893ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com int scale = (int)SkScalarMul(width, 256); 89432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com int alpha = origPaint.getAlpha() * scale >> 8; 895a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 896ebdeeb8a018f2df01e190fd961d68a94f0e0fcb9reed@android.com // pretend to be a hairline, with a modulated alpha 89732e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.set(origPaint); 89832e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.get()->setAlpha(alpha); 89932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com lazyPaint.get()->setStrokeWidth(0); 90032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint = lazyPaint.get(); 9018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 903a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 90432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { 90532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com doFill = paint->getFillPath(*pathPtr, &tmpPath); 9068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr = &tmpPath; 9078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 908a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 90932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()) { 9108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 91132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, 91232e5d97ccf60f859db063ebd6e903c362e625767reed@google.com &fClip->getBounds(), paint->getMaskFilter(), &mask, 9138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::kComputeBoundsAndRenderImage_CreateMode)) { 91432e5d97ccf60f859db063ebd6e903c362e625767reed@google.com this->drawDevMask(mask, *paint); 9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask::FreeImage(mask.fImage); 9168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // avoid possibly allocating a new path in transform if we can 9218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; 9228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform the path into device space 9248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathPtr->transform(*matrix, devPathPtr); 9258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 92632e5d97ccf60f859db063ebd6e903c362e625767reed@google.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint); 9278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // how does filterPath() know to fill or hairline the path??? <mrr> 92932e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->getMaskFilter() && 93032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fClip, 93132e5d97ccf60f859db063ebd6e903c362e625767reed@google.com fBounder, blitter.get())) { 9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // filterPath() called the blitter, so we're done 9338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 93532e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (fBounder && !fBounder->doPath(*devPathPtr, *paint, doFill)) { 9368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 9378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 94032e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiFillPath(*devPathPtr, *fClip, blitter.get()); 9428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillPath(*devPathPtr, *fClip, blitter.get()); 9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 94632e5d97ccf60f859db063ebd6e903c362e625767reed@google.com if (paint->isAntiAlias()) { 9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::AntiHairPath(*devPathPtr, fClip, blitter.get()); 9488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 9498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::HairPath(*devPathPtr, fClip, blitter.get()); 9508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 9528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9540baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com/** For the purposes of drawing bitmaps, if a matrix is "almost" translate 9550baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com go ahead and treat it as if it were, so that subsequent code can go fast. 9560baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com */ 9570baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.comstatic bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { 9580baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkMatrix::TypeMask mask = matrix.getType(); 9590baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com 9600baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 9610baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return false; 9620baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9630baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (mask & SkMatrix::kScale_Mask) { 9640baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sx = matrix[SkMatrix::kMScaleX]; 9650baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com SkScalar sy = matrix[SkMatrix::kMScaleY]; 9660baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int w = bitmap.width(); 9670baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int h = bitmap.height(); 9680baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w))); 9690baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h))); 9700baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return sw == w && sh == h; 9710baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com } 9720baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com // if we got here, we're either kTranslate_Mask or identity 9730baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com return true; 9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, 9778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(bitmap.getConfig() == SkBitmap::kA8_Config); 9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 980a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com if (just_translate(*fMatrix, bitmap)) { 9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(fMatrix->getTranslateX()); 9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(fMatrix->getTranslateY()); 9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 9858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 9868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 9878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = bitmap.rowBytes(); 9888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = bitmap.getAddr8(0, 0); 989a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 9908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 9918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // need to xform the bitmap first 9928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 9938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 994a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapRect(&r); 9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.round(&mask.fBounds); 999a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // set the mask's bounds to the transformed bitmap-bounds, 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // clipped to the actual device 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devBounds; 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need intersect(l, t, r, b) on irect 10068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!mask.fBounds.intersect(devBounds)) { 10078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1010543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com 10118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fFormat = SkMask::kA8_Format; 10128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = SkAlign4(mask.fBounds.width()); 1013543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask.computeImageSize(); 1014543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 1015543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // the mask is too big to allocated, draw nothing 1016543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return; 1017543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 10188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // allocate (and clear) our temp buffer to hold the transformed bitmap 10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoMalloc storage(size); 10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)storage.get(); 10228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask.fImage, 0, size); 1023a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now draw our bitmap(src) into mask(dst), transformed by the matrix 10258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 10268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap device; 10278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), 10288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.height(), mask.fRowBytes); 10298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com device.setPixels(mask.fImage); 1030a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas c(device); 10328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need the unclipped top/left for the translate 10338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.translate(-SkIntToScalar(mask.fBounds.fLeft), 10348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 10358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com c.concat(*fMatrix); 10363469c76c40790b409621fd7eff34f56240718549reed@android.com 10373469c76c40790b409621fd7eff34f56240718549reed@android.com // We can't call drawBitmap, or we'll infinitely recurse. Instead 1038fb12c3e6ba84f95dc15fbaddc239dede0ba1d60ereed@android.com // we manually build a shader and draw that into our new mask 10393469c76c40790b409621fd7eff34f56240718549reed@android.com SkPaint tmpPaint; 10403469c76c40790b409621fd7eff34f56240718549reed@android.com tmpPaint.setFlags(paint.getFlags()); 104140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, tmpPaint); 10423469c76c40790b409621fd7eff34f56240718549reed@android.com SkRect rr; 10433469c76c40790b409621fd7eff34f56240718549reed@android.com rr.set(0, 0, SkIntToScalar(bitmap.width()), 10443469c76c40790b409621fd7eff34f56240718549reed@android.com SkIntToScalar(bitmap.height())); 104540c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com c.drawRect(rr, install.paintWithShader()); 10468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawDevMask(mask, paint); 10488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& m, const SkRegion& c, 10528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& srcR) { 10538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect dstR; 10548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect devIR; 1055a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.mapRect(&dstR, srcR); 1057a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com dstR.roundOut(&devIR); 10588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return c.quickReject(devIR); 10598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool clipped_out(const SkMatrix& matrix, const SkRegion& clip, 10628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int width, int height) { 10638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 10648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); 10658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return clipped_out(matrix, clip, r); 10668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 10678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, 106940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1070f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 10718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 10738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 10748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 10758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.getConfig() == SkBitmap::kNo_Config || 107640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 10778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1079a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1080a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#ifndef SK_ALLOW_OVER_32K_BITMAPS 10818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // run away on too-big bitmaps for now (exceed 16.16) 10828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.width() > 32767 || bitmap.height() > 32767) { 10838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1085a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#endif 1086a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 108740c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 108840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 1089a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 10908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 10918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!matrix.setConcat(*fMatrix, prematrix)) { 10928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (clipped_out(matrix, *fClip, bitmap.width(), bitmap.height())) { 10968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 10978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 10988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1099218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (fBounder && just_translate(matrix, bitmap)) { 1100218521e15706c4377b1be49d931c4d7c8d597445reed@android.com SkIRect ir; 1101218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t ix = SkScalarRound(matrix.getTranslateX()); 1102218521e15706c4377b1be49d931c4d7c8d597445reed@android.com int32_t iy = SkScalarRound(matrix.getTranslateY()); 1103218521e15706c4377b1be49d931c4d7c8d597445reed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 1104218521e15706c4377b1be49d931c4d7c8d597445reed@android.com if (!fBounder->doIRect(ir)) { 1105218521e15706c4377b1be49d931c4d7c8d597445reed@android.com return; 1106218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1107218521e15706c4377b1be49d931c4d7c8d597445reed@android.com } 1108218521e15706c4377b1be49d931c4d7c8d597445reed@android.com 1109218521e15706c4377b1be49d931c4d7c8d597445reed@android.com // only lock the pixels if we passed the clip and bounder tests 11108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoLockPixels alp(bitmap); 11118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // after the lock, check if we are valid 11128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!bitmap.readyToDraw()) { 11138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11160baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com if (bitmap.getConfig() != SkBitmap::kA8_Config && 11170baf19375466cfc24c96532df406e7c5b1d1aae8reed@android.com just_translate(matrix, bitmap)) { 11188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int ix = SkScalarRound(matrix.getTranslateX()); 11198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int iy = SkScalarRound(matrix.getTranslateY()); 11208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 11218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 11228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ix, iy, storage, sizeof(storage)); 11238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 11248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 11258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 11278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); 11288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, ir); 11308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 11318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 11338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 11348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 11358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if 0 11398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("---- MISSING sprite case: config=%d [%d %d], device=%d, xfer=%p, alpha=0x%X colorFilter=%p\n", 11408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.config(), bitmap.width(), bitmap.height(), fBitmap->config(), 11418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.getXfermode(), paint.getAlpha(), paint.getColorFilter()); 11428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 11438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1144a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now make a temp draw on the stack, and use it 11468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // 11478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 11488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 1149a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (bitmap.getConfig() == SkBitmap::kA8_Config) { 11518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawBitmapAsMask(bitmap, paint); 11528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 115340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 11548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 11568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(0, 0, SkIntToScalar(bitmap.width()), 11578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(bitmap.height())); 1158a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this ok if paint has a rasterizer? 115940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, install.paintWithShader()); 11608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 11628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, 116440c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& origPaint) const { 1165f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 1166a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 11678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 11688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isEmpty() || 11698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.width() == 0 || bitmap.height() == 0 || 11708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bitmap.getConfig() == SkBitmap::kNo_Config || 117140c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com (origPaint.getAlpha() == 0 && origPaint.getXfermode() == NULL)) { 11728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect bounds; 11768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); 11778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->quickReject(bounds)) { 11798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // nothing to draw 11808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118240c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkPaint paint(origPaint); 118340c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com paint.setStyle(SkPaint::kFill_Style); 11848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == paint.getColorFilter()) { 11868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t storage[kBlitterStorageLongCount]; 11878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, 11888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x, y, storage, sizeof(storage)); 11898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (blitter) { 11918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoTPlacementDelete<SkBlitter> ad(blitter, storage); 11928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder && !fBounder->doIRect(bounds)) { 11948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 11958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 11968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 11978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator iter(*fClip, bounds); 11988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = iter.rect(); 11998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) { 12018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!cr.isEmpty()); 12028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com blitter->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height()); 12038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 12058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 120840c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com SkAutoBitmapShaderInstall install(bitmap, paint); 120940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com const SkPaint& shaderPaint = install.paintWithShader(); 12108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 12138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // get a scalar version of our rect 12158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.set(bounds); 12168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // tell the shader our offset 12188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(r.fLeft, r.fTop); 121940c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com shaderPaint.getShader()->setLocalMatrix(matrix); 1220a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw(*this); 12228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.reset(); 12238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 12248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // call ourself with a rect 1225a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com // is this OK if paint has a rasterizer? 122640c2ba27b6e5c6a4b6c073264f8c0a7c86355abereed@google.com draw.drawRect(r, shaderPaint); 12278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 12308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalerContext.h" 12328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGlyphCache.h" 12338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h" 12348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, 12368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char text[], size_t byteLength, SkVector* stopVector) { 12378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed x = 0, y = 0; 12388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 12398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 1241a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 12428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 12438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // don't need x, y here, since all subpixel variants will have the 12448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // same advance 12458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 12468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += autokern.adjust(glyph) + glyph.fAdvanceX; 12488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y += glyph.fAdvanceY; 12498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); 12518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(text == stop); 12538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText_asPaths(const char text[], size_t byteLength, 12568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, 12578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 1258f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 12598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 12618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 12638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setScale(iter.getPathScale(), iter.getPathScale()); 12648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(x, y); 12658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 12678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos, prevXPos = 0; 12688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 12708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(xpos - prevXPos, 0); 1271f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkPaint& pnt = iter.getPaint(); 1272f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1273f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, *iterPath, pnt, &matrix, false); 1274f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1275f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(*iterPath, pnt, &matrix, false); 1276f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 12778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com prevXPos = xpos; 12788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void draw_paint_rect(const SkDraw* draw, const SkPaint& paint, 12828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkRect& r, SkScalar textSize) { 12838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getStyle() == SkPaint::kFill_Style) { 12848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw->drawRect(r, paint); 12858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 12868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 12878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStrokeWidth(SkScalarMul(textSize, paint.getStrokeWidth())); 12888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw->drawRect(r, p); 12898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 12908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 12918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void handle_aftertext(const SkDraw* draw, const SkPaint& paint, 12938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width, const SkPoint& start) { 12948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t flags = paint.getFlags(); 12958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (flags & (SkPaint::kUnderlineText_Flag | 12978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint::kStrikeThruText_Flag)) { 12988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar textSize = paint.getTextSize(); 12998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar height = SkScalarMul(textSize, kStdUnderline_Thickness); 13008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect r; 13018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = start.fX; 13038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = start.fX + width; 13048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (flags & SkPaint::kUnderlineText_Flag) { 13068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar offset = SkScalarMulAdd(textSize, kStdUnderline_Offset, 13078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com start.fY); 13088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = offset; 13098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = offset + height; 13108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_paint_rect(draw, paint, r, textSize); 13118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (flags & SkPaint::kStrikeThruText_Flag) { 13138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar offset = SkScalarMulAdd(textSize, kStdStrikeThru_Offset, 13148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com start.fY); 13158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = offset; 13168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = offset + height; 13178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_paint_rect(draw, paint, r, textSize); 13188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// disable warning : local variable used without having been initialized 1323a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com#if defined _WIN32 && _MSC_VER >= 1300 13248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( push ) 13258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( disable : 4701 ) 13268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 13278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 13298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RectClip(const SkDraw1Glyph& state, 1331f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1332f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1333f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1334f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClip->isRect()); 13378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(state.fClipBounds == state.fClip->getBounds()); 13398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int right = left + glyph.fWidth; 13448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int bottom = top + glyph.fHeight; 13458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect storage; 13488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds = &mask.fBounds; 13498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, right, bottom); 13518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // this extra test is worth it, assuming that most of the time it succeeds 13538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // since we can avoid writing to storage 13548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { 13558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) 13568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds = &storage; 13588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1359a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1360a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com uint8_t* aa = (uint8_t*)glyph.fImage; 13618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; // can't rasterize glyph 13658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 13696c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 13708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = aa; 13718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, *bounds); 13728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 13738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_NoBounder_RgnClip(const SkDraw1Glyph& state, 1375f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1376f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1377f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1378f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 13798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 13808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!state.fClip->isRect()); 13818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(NULL == state.fBounder); 13828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 13848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 13868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 13878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 13898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 13908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 13928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 13938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 13948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 13968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 13978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 13988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 13998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1400a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 14018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 14026c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 14038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 14048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 14058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 14068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 14078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 14088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void D1G_Bounder(const SkDraw1Glyph& state, 1412f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fx, SkFixed fy, 1413f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph) { 1414f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int left = SkFixedFloor(fx); 1415f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int top = SkFixedFloor(fy); 14168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); 14178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask mask; 14198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com left += glyph.fLeft; 14218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com top += glyph.fTop; 14228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); 14248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); 14258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!clipper.done()) { 14278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = clipper.rect(); 14288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* aa = (const uint8_t*)glyph.fImage; 14298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aa = (uint8_t*)state.fCache->findImage(glyph); 14318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == aa) { 14328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 14338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1435d055c1fde2128514167b315f4d104b177e04a3dereed@android.com 1436d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // we need to pass the origin, which we approximate with our 1437d055c1fde2128514167b315f4d104b177e04a3dereed@android.com // (unadjusted) left,top coordinates (the caller called fixedfloor) 1438d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (state.fBounder->doIRectGlyph(cr, 1439d055c1fde2128514167b315f4d104b177e04a3dereed@android.com left - glyph.fLeft, 1440d055c1fde2128514167b315f4d104b177e04a3dereed@android.com top - glyph.fTop, glyph)) { 14418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fRowBytes = glyph.rowBytes(); 14426c14b43a840c791699747ba4cc0ed5abf2bda218reed@android.com mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); 14438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask.fImage = (uint8_t*)aa; 14448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 14458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fBlitter->blitMask(mask, cr); 14468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipper.next(); 14478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (!clipper.done()); 14488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1452fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool hasCustomD1GProc(const SkDraw& draw) { 1453fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return draw.fProcs && draw.fProcs->fD1GProc; 1454fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1455fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 1456fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.comstatic bool needsRasterTextBlit(const SkDraw& draw) { 1457fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com return !hasCustomD1GProc(draw); 1458fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com} 1459fd4236ecc1d5eb1bb48ca9dc33df5e9051c3036ereed@google.com 14608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, 14618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache) { 14628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDraw = draw; 14638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBounder = draw->fBounder; 14648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip = draw->fClip; 14658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClipBounds = fClip->getBounds(); 14668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBlitter = blitter; 14678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCache = cache; 14688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14691d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*draw)) { 14708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return draw->fProcs->fD1GProc; 14718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == fBounder) { 14748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClip->isRect()) { 14758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RectClip; 14768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_NoBounder_RgnClip; 14788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return D1G_Bounder; 14818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 14828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 14838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comenum RoundBaseline { 14858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDont_Round_Baseline, 14868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kRound_X_Baseline, 14878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kRound_Y_Baseline 14888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 14898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 14908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic RoundBaseline computeRoundBaseline(const SkMatrix& mat) { 14918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (mat[1] == 0 && mat[3] == 0) { 14928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we're 0 or 180 degrees, round the y coordinate of the baseline 14938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return kRound_Y_Baseline; 14948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (mat[0] == 0 && mat[4] == 0) { 14958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we're 90 or 270 degrees, round the x coordinate of the baseline 14968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return kRound_X_Baseline; 14978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 14988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return kDont_Round_Baseline; 14998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 15018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 15038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawText(const char text[], size_t byteLength, 15058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x, SkScalar y, const SkPaint& paint) const { 15068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 15078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1508f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 15098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 15118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 15128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 15138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 15148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 15158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar underlineWidth = 0; 15188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint underlineStart; 15198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com underlineStart.set(0, 0); // to avoid warning 15218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getFlags() & (SkPaint::kUnderlineText_Flag | 15228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint::kStrikeThruText_Flag)) { 15238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com underlineWidth = paint.measureText(text, byteLength); 15248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar offsetX = 0; 15268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 15278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offsetX = SkScalarHalf(underlineWidth); 15288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (paint.getTextAlign() == SkPaint::kRight_Align) { 15298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com offsetX = underlineWidth; 15308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com underlineStart.set(x - offsetX, y); 15328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 15358d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 15368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->drawText_asPaths(text, byteLength, x, y, paint); 15378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com handle_aftertext(this, paint, underlineWidth, underlineStart); 15388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 15398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 15428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1543f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 1544f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed finalFYMask = ~0xFFFF; // trunc fy; 15451d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1546f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1547f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1548f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1549f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1550f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com finalFYMask = ~0; // don't truncate 1551f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1552f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1553f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1554f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 15558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1556a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform our starting point 15588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 15598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint loc; 1560f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix->mapXY(x, y, &loc); 15618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x = loc.fX; 15628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y = loc.fY; 15638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 15668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 15678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector stop; 15688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com measure_text(cache, glyphCacheProc, text, byteLength, &stop); 15708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopX = stop.fX; 15728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar stopY = stop.fY; 15738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 15748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 15758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopX = SkScalarHalf(stopX); 15768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com stopY = SkScalarHalf(stopY); 15778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x -= stopX; 15798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com y -= stopY; 15808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1581a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 15828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(x); 15838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(y); 15848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 15858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1586f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1587f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 15888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 1589f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com RoundBaseline roundBaseline = computeRoundBaseline(*matrix); 15908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (kRound_Y_Baseline == roundBaseline) { 1591f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 1592f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com// fy = (fy + 0x8000) & ~0xFFFF; 15938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (kRound_X_Baseline == roundBaseline) { 1594f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 15958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 15968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1597f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // apply the bias here, so we don't have to add 1/2 in the loop 1598f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx += SK_FixedHalf; 1599f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fy += SK_FixedHalf; 160039ce0ac09a375aab18659b1a4ed0c503b0b81a4creed@google.com fyMask &= finalFYMask; 16018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16021d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 16031d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 16041d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 16051d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 16061d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 16078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoKern autokern; 16088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph d1g; 16098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 16108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1612f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 16138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += autokern.adjust(glyph); 16158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 1617f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, glyph); 16188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx += glyph.fAdvanceX; 16208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy += glyph.fAdvanceY; 16218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (underlineWidth) { 16248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com autoCache.release(); // release this now to free up the RAM 16258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com handle_aftertext(this, paint, underlineWidth, underlineStart); 16268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// last parameter is interpreted as SkFixed [x, y] 16308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// return the fixed position, which may be rounded or not by the caller 16318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// e.g. subpixel doesn't round 16328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); 16338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); 16378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), 16428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); 16438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, 16468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint* dst) { 16478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, 16488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalarToFixed(loc.fY) - glyph.fAdvanceY); 16498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic AlignProc pick_align_proc(SkPaint::Align align) { 16528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static const AlignProc gProcs[] = { 16538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com leftAlignProc, centerAlignProc, rightAlignProc 16548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1655a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); 16578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return gProcs[align]; 16598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 16608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass TextMapState { 16628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 16638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mutable SkPoint fLoc; 1664a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState(const SkMatrix& matrix, SkScalar y) 16668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} 16678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); 1669a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc pickProc(int scalarsPerPosition); 1671a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 16738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& fMatrix; 16748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc fProc; 16758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fY; // ignored by MapXYProc 16768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // these are only used by Only... procs 16778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fScaleX, fTransX, fTransformedY; 16788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXProc(const TextMapState& state, const SkScalar pos[]) { 16808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc); 16818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1682a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapXYProc(const TextMapState& state, const SkScalar pos[]) { 16848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc); 16858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1686a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyScaleXProc(const TextMapState& state, 16888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX, 16908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fTransformedY); 16918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1692a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 16938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void MapOnlyTransXProc(const TextMapState& state, 16948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[]) { 16958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.fLoc.set(*pos + state.fTransX, state.fTransformedY); 16968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 16978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 16988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 16998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comTextMapState::Proc TextMapState::pickProc(int scalarsPerPosition) { 17008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1701a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (1 == scalarsPerPosition) { 17038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unsigned mtype = fMatrix.getType(); 17048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 17058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXProc; 17068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fScaleX = fMatrix.getScaleX(); 17088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransX = fMatrix.getTranslateX(); 17098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) + 17108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix.getTranslateY(); 17118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return (mtype & SkMatrix::kScale_Mask) ? 17128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com MapOnlyScaleXProc : MapOnlyTransXProc; 17138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return MapXYProc; 17168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 17188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////////////// 17208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawPosText(const char text[], size_t byteLength, 17228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkScalar pos[], SkScalar constY, 17238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scalarsPerPosition, const SkPaint& paint) const { 17248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 17258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 17268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1727f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDEBUGCODE(this->validate();) 17288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 17308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 17318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 17328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 17338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 17348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (/*paint.isLinearText() ||*/ 17378d430185e08d2067584837a76b7193b803fee7a0tomhudson@google.com (fMatrix->hasPerspective())) { 17388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // TODO !!!! 17398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// this->drawText_asPaths(text, byteLength, x, y, paint); 17408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 17418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1743f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkMatrix* matrix = fMatrix; 17441d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (hasCustomD1GProc(*this)) { 1745f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // only support the fMVMatrix (for now) for the GPU case, which also 1746f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // sets the fD1GProc 1747f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMVMatrix) { 1748f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com matrix = fMVMatrix; 1749f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1750f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1751a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1753f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoGlyphCache autoCache(paint, matrix); 17548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkGlyphCache* cache = autoCache.getCache(); 1755a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17561d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com SkAutoBlitterChoose blitter; 17571d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com if (needsRasterTextBlit(*this)) { 17581d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com blitter.choose(*fBitmap, *matrix, paint); 17591d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com } 17601d6ee0bd4db7f3b676209341214641d9af5a965freed@google.com 17618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* stop = text + byteLength; 17628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com AlignProc alignProc = pick_align_proc(paint.getTextAlign()); 17638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph d1g; 17648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw1Glyph::Proc proc = d1g.init(this, blitter.get(), cache); 1765f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com TextMapState tms(*matrix, constY); 17668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); 17678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isSubpixelText()) { 17698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // maybe we should skip the rounding if linearText is set 1770f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com RoundBaseline roundBaseline = computeRoundBaseline(*matrix); 17718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkPaint::kLeft_Align == paint.getTextAlign()) { 17738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 1774a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1776a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx = SkScalarToFixed(tms.fLoc.fX); 17788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fy = SkScalarToFixed(tms.fLoc.fY); 1779f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1780f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 17818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (kRound_Y_Baseline == roundBaseline) { 1783f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 17848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (kRound_X_Baseline == roundBaseline) { 1785f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 17868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1787a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1788f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 1789f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fx & fxMask, fy & fyMask); 1790a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 17918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 1792f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, glyph); 17938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 17958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 17968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 17978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 17988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph* glyph = &glyphCacheProc(cache, &text, 0, 0); 1799a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph->fWidth) { 18018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvX = glyph->fAdvanceX;) 18028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(SkFixed prevAdvY = glyph->fAdvanceY;) 18038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fx, fy; 1805f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fxMask = ~0; 1806f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkFixed fyMask = ~0; 18078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1808a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 18108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 18118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, *glyph, &fixedLoc); 18128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fx = fixedLoc.fX; 18138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fy = fixedLoc.fY; 18148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (kRound_Y_Baseline == roundBaseline) { 1816f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fyMask = 0; 18178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (kRound_X_Baseline == roundBaseline) { 1818f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fxMask = 0; 18198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1821a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // have to call again, now that we've been "aligned" 1823f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com glyph = &glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); 18248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the assumption is that the advance hasn't changed 18258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvX == glyph->fAdvanceX); 18268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(prevAdvY == glyph->fAdvanceY); 1827a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1828f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fx, fy, *glyph); 18298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 18318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // not subpixel 18348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (text < stop) { 18358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // the last 2 parameters are ignored 18368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1837a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (glyph.fWidth) { 18398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tmsProc(tms, pos); 1840a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 18418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fixedLoc; 18428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com alignProc(tms.fLoc, glyph, &fixedLoc); 1843a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 1844f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com proc(d1g, fixedLoc.fX + SK_FixedHalf, 1845f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fixedLoc.fY + SK_FixedHalf, glyph); 18468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos += scalarsPerPosition; 18488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined _WIN32 && _MSC_VER >= 1300 18538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#pragma warning ( pop ) 18548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 18558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 18578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathMeasure.h" 18598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpoints(SkPoint dst[], const SkPoint src[], int count, 18618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure& meas, const SkMatrix& matrix) { 18628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix::MapXYProc proc = matrix.getMapXYProc(); 18638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 18658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pos; 18668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkVector tangent; 18678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com proc(matrix, src[i].fX, src[i].fY, &pos); 18698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sx = pos.fX; 18708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar sy = pos.fY; 18718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com meas.getPosTan(sx, &pos, &tangent); 18738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* This is the old way (that explains our approach but is way too slow 18758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 18768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint pt; 18778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pt.set(sx, sy); 18798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setSinCos(tangent.fY, tangent.fX); 18808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.preTranslate(-sx, 0); 18818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.postTranslate(pos.fX, pos.fY); 18828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.mapPoints(&dst[i], &pt, 1); 18838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 18848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy), 18858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pos.fY + SkScalarMul(tangent.fX, sy)); 18868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 18878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 18888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* TODO 18908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 18918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Need differentially more subdivisions when the follow-path is curvy. Not sure how to 18928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com determine that, but we need it. I guess a cheap answer is let the caller tell us, 18938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out. 18948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 18958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, 18968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& matrix) { 18978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Iter iter(src, false); 18988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint srcP[4], dstP[3]; 18998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath::Verb verb; 19008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) { 19028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (verb) { 19038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kMove_Verb: 19048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 1, meas, matrix); 19058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->moveTo(dstP[0]); 19068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kLine_Verb: 19088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // turn lines into quads to look bendy 19098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX); 19108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY); 19118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, srcP, 2, meas, matrix); 19128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 19138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kQuad_Verb: 19158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 2, meas, matrix); 19168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->quadTo(dstP[0], dstP[1]); 19178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kCubic_Verb: 19198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpoints(dstP, &srcP[1], 3, meas, matrix); 19208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->cubicTo(dstP[0], dstP[1], dstP[2]); 19218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkPath::kClose_Verb: 19238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst->close(); 19248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 19268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(!"unknown verb"); 19278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 19288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawTextOnPath(const char text[], size_t byteLength, 19338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& follow, const SkMatrix* matrix, 19348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 19358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(byteLength == 0 || text != NULL); 19368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // nothing to draw 19388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (text == NULL || byteLength == 0 || 19398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClip->isEmpty() || 19408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 19418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 19428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTextToPathIter iter(text, byteLength, paint, true, true); 19458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPathMeasure meas(follow, false); 19468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar hOffset = 0; 19478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to measure first 19498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() != SkPaint::kLeft_Align) { 19508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar pathLen = meas.getLength(); 19518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getTextAlign() == SkPaint::kCenter_Align) { 19528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathLen = SkScalarHalf(pathLen); 19538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hOffset += pathLen; 19558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath* iterPath; 19588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar xpos; 19598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix scaledMatrix; 19608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar scale = iter.getPathScale(); 19618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scaledMatrix.setScale(scale, scale); 1963a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 19648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while ((iterPath = iter.next(&xpos)) != NULL) { 19658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 19668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m(scaledMatrix); 19678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postTranslate(xpos + hOffset, 0); 19698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (matrix) { 19708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.postConcat(*matrix); 19718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com morphpath(&tmp, *iterPath, meas, m); 1973f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fDevice) { 1974f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true); 1975f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 1976f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->drawPath(tmp, iter.getPaint(), NULL, true); 1977f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 19788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 19798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 19808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1981cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#ifdef ANDROID 1982cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.comvoid SkDraw::drawPosTextOnPath(const char text[], size_t byteLength, 1983cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPoint pos[], const SkPaint& paint, 1984cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath& path, const SkMatrix* matrix) const { 1985cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // nothing to draw 1986cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (text == NULL || byteLength == 0 || fClip->isEmpty() || 1987cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 1988cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com return; 1989cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 1990cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1991cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix scaledMatrix; 1992cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPathMeasure meas(path, false); 1993cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1994cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc( 1995cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint::kForward_TextBufferDirection, true); 1996cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 1997cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Copied (modified) from SkTextToPathIter constructor to setup paint 1998cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPaint tempPaint(paint); 1999cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2000cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setLinearText(true); 2001cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lookup 2002cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2003cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (tempPaint.getPathEffect() == NULL && !(tempPaint.getStrokeWidth() > 0 2004cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com && tempPaint.getStyle() != SkPaint::kFill_Style)) { 2005cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setStyle(SkPaint::kFill_Style); 2006cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com tempPaint.setPathEffect(NULL); 2007cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2008cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // End copied from SkTextToPathIter constructor 2009cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2010cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // detach cache 2011cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache* cache = tempPaint.detachCache(NULL); 2012cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2013cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Must set scale, even if 1 2014cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkScalar scale = SK_Scalar1; 2015cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com scaledMatrix.setScale(scale, scale); 2016cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2017cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // Loop over all glyph ids 2018cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com for (const char* stop = text + byteLength; text < stop; pos++) { 2019cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2020cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkGlyph& glyph = glyphCacheProc(cache, &text); 2021cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkPath tmp; 2022cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2023cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com const SkPath* glyphPath = cache->findPath(glyph); 2024cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (glyphPath == NULL) { 2025cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com continue; 2026cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2027cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2028cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkMatrix m(scaledMatrix); 2029cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postTranslate(pos->fX, 0); 2030cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2031cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com if (matrix) { 2032cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com m.postConcat(*matrix); 2033cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2034cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2035cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com morphpath(&tmp, *glyphPath, meas, m); 2036cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com this->drawPath(tmp, tempPaint); 2037cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2038cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com } 2039cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 2040cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com // re-attach cache 2041cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com SkGlyphCache::AttachCache(cache); 2042cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com} 2043cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com#endif 2044cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5djsollen@google.com 20458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/////////////////////////////////////////////////////////////////////////////// 20468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct VertState { 20488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int f0, f1, f2; 20498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState(int vCount, const uint16_t indices[], int indexCount) 20518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fIndices(indices) { 20528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCurrIndex = 0; 20538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (indices) { 20548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = indexCount; 20558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 20568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCount = vCount; 20578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2059a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 2060a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com typedef bool (*Proc)(VertState*); 20618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Proc chooseProc(SkCanvas::VertexMode mode); 20628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 20648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCount; 20658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int fCurrIndex; 20668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* fIndices; 2067a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 20688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool Triangles(VertState*); 20698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TrianglesX(VertState*); 20708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStrip(VertState*); 20718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleStripX(VertState*); 20728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFan(VertState*); 20738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static bool TriangleFanX(VertState*); 20748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 20758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::Triangles(VertState* state) { 20778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 20828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 20838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 20848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 20878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 20888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TrianglesX(VertState* state) { 20898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 20908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 20918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 20928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 20938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 20948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 20958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 20968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 20978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 3; 20988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 20998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStrip(VertState* state) { 21028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 21078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 21088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 1; 21098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 0; 21108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = index + 0; 21128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 21138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleStripX(VertState* state) { 21198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 21208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 21258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index & 1) { 21268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 1]; 21278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 0]; 21288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 21298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[index + 0]; 21308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 21318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFan(VertState* state) { 21378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = 0; 21428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = index + 1; 21438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = index + 2; 21448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool VertState::TriangleFanX(VertState* state) { 21498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t* indices = state->fIndices; 21508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index = state->fCurrIndex; 21518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (index + 3 > state->fCount) { 21528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 21538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f0 = indices[0]; 21558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f1 = indices[index + 1]; 21568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->f2 = indices[index + 2]; 21578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state->fCurrIndex = index + 1; 21588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 21598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comVertState::Proc VertState::chooseProc(SkCanvas::VertexMode mode) { 21628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (mode) { 21638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangles_VertexMode: 21648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TrianglesX : Triangles; 21658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleStrip_VertexMode: 21668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleStripX : TriangleStrip; 21678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SkCanvas::kTriangleFan_VertexMode: 21688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fIndices ? TriangleFanX : TriangleFan; 21698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default: 21708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return NULL; 21718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 21728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRegion*, 21758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBlitter*); 21768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic HairProc ChooseHairProc(bool doAntiAlias) { 21788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; 21798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool texture_to_matrix(const VertState& state, const SkPoint verts[], 21828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint texs[], SkMatrix* matrix) { 21838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src[3], dst[3]; 2184a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 21858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[0] = texs[state.f0]; 21868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[1] = texs[state.f1]; 21878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src[2] = texs[state.f2]; 21888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[0] = verts[state.f0]; 21898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[1] = verts[state.f1]; 21908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst[2] = verts[state.f2]; 21918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return matrix->setPolyToPoly(src, dst, 3); 21928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 21938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkTriColorShader : public SkShader { 21958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 21968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader() {} 21978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 21988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); 2199a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count); 2201a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 22038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader(SkFlattenableReadBuffer& buffer) : SkShader(buffer) {} 2204a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual Factory getFactory() { return CreateProc; } 2206a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 22088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix fDstToUnit; 22098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPMColor fColors[3]; 2210a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 22128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(SkTriColorShader, (buffer)); 22138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkShader INHERITED; 22158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 22168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkTriColorShader::setup(const SkPoint pts[], const SkColor colors[], 22188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int index0, int index1, int index2) { 2219a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[0] = SkPreMultiplyColor(colors[index0]); 22218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[1] = SkPreMultiplyColor(colors[index1]); 22228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fColors[2] = SkPreMultiplyColor(colors[index2]); 2223a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m, im; 22258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 22268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(0, pts[index1].fX - pts[index0].fX); 22278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(1, pts[index2].fX - pts[index0].fX); 22288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(2, pts[index0].fX); 22298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(3, pts[index1].fY - pts[index0].fY); 22308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(4, pts[index2].fY - pts[index0].fY); 22318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.set(5, pts[index0].fY); 22328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!m.invert(&im)) { 22338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 22348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fDstToUnit.setConcat(im, this->getTotalInverse()); 22368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h" 2239689411a87ca7d19abe04b5c9baff26bd96b2123ereed@android.com#include "SkComposeShader.h" 22408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic int ScalarTo256(SkScalar v) { 22428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale = SkScalarToFixed(v) >> 8; 22438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale < 0) { 22448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 0; 22458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale > 255) { 22478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale = 255; 22488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkAlpha255To256(scale); 22508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkTriColorShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { 22538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src; 2254a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 22568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 22578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x += 1; 2258a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale1 = ScalarTo256(src.fX); 22608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale2 = ScalarTo256(src.fY); 22618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int scale0 = 256 - scale1 - scale2; 22628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale0 < 0) { 22638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (scale1 > scale2) { 22648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale2 = 256 - scale1; 22658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 22668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale1 = 256 - scale2; 22678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com scale0 = 0; 22698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2270a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 22728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[1], scale1) + 22738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAlphaMulQ(fColors[2], scale2); 22748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 22758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 22768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 22778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, 22788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint vertices[], const SkPoint textures[], 22798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkColor colors[], SkXfermode* xmode, 22808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint16_t indices[], int indexCount, 22818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) const { 22828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(0 == count || NULL != vertices); 2283a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // abort early if there is nothing to draw 22858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (count < 3 || (indices && indexCount < 3) || fClip->isEmpty() || 22868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 22878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 22888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2289a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // transform out vertices into device coordinates 22918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoSTMalloc<16, SkPoint> storage(count); 22928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint* devVerts = storage.get(); 22938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix->mapPoints(devVerts, vertices, count); 2294a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 22958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fBounder) { 22968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect bounds; 22978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.set(devVerts, count); 22988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!fBounder->doRect(bounds, paint)) { 22998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 23008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2302a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* 23048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com We can draw the vertices in 1 of 4 ways: 23058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - solid color (no shader/texture[], no colors[]) 23078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just colors (no shader/texture[], has colors[]) 23088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - just texture (has shader/texture[], no colors[]) 23098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com - colors * texture (has shader/texture[], has colors[]) 2310a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Thus for texture drawing, we need both texture[] and a shader. 23128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 23138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTriColorShader triShader; // must be above declaration of p 23158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p(paint); 23168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* shader = p.getShader(); 23188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == shader) { 23198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we have no shader, we ignore the texture coordinates 23208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textures = NULL; 23218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else if (NULL == textures) { 23228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // if we don't have texture coordinates, ignore the shader 23238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(NULL); 23248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader = NULL; 23258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup the custom shader (if needed) 23288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == textures) { 23308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // just colors (no texture) 23318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(&triShader); 23328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // colors * texture 23348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(shader); 23358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool releaseMode = false; 23368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL == xmode) { 2337845fdaca174f4675e9acc164b510e3a5ffa9053creed@android.com xmode = SkXfermode::Create(SkXfermode::kMultiply_Mode); 23388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com releaseMode = true; 23398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkShader* compose = SkNEW_ARGS(SkComposeShader, 23418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (&triShader, shader, xmode)); 23428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setShader(compose)->unref(); 23438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (releaseMode) { 23448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com xmode->unref(); 23458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 23498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); 23508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // setup our state and function pointer for iterating triangles 23518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState state(count, indices, indexCount); 23528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com VertState::Proc vertProc = state.chooseProc(vmode); 2353a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures || NULL != colors) { 23558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix localM, tempM; 23568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasLocalM = shader && shader->getLocalMatrix(&localM); 2357a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setContext(*fBitmap, p, *fMatrix)) { 23608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com colors = NULL; 23618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2363a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 23648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 23658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != textures) { 23668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (texture_to_matrix(state, vertices, textures, &tempM)) { 23678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com tempM.postConcat(localM); 23698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(tempM); 23718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to recal setContext since we changed the local matrix 23728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!shader->setContext(*fBitmap, p, *fMatrix)) { 23738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != colors) { 23788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!triShader.setup(vertices, colors, 23798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com state.f0, state.f1, state.f2)) { 23808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com continue; 23818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillTriangle(devVerts[state.f0], devVerts[state.f1], 23848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com devVerts[state.f2], fClip, blitter.get()); 23858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // now restore the shader's original local matrix 23878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (NULL != shader) { 23888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (hasLocalM) { 23898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->setLocalMatrix(localM); 23908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com shader->resetLocalMatrix(); 23928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 23948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 23958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // no colors[] and no texture 23968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); 23978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (vertProc(&state)) { 23988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f0], devVerts[state.f1], fClip, blitter.get()); 23998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f1], devVerts[state.f2], fClip, blitter.get()); 24008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com hairProc(devVerts[state.f2], devVerts[state.f0], fClip, blitter.get()); 24018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24050a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24060a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 24098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2410f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkDraw::validate() const { 24118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fBitmap != NULL); 24128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fMatrix != NULL); 24138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fClip != NULL); 24148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkIRect& cr = fClip->getBounds(); 24168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect br; 24178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2418f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com br.set(0, 0, fBitmap->width(), fBitmap->height()); 24198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(cr.isEmpty() || br.contains(cr)); 2420f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 2421f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // assert that both are null, or both are not-null 2422f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkASSERT(!fMVMatrix == !fExtMatrix); 24238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 24268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24270a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com/////////////////////////////////////////////////////////////////////////////// 24280a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com 24290a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.comSkBounder::SkBounder() { 24300a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com // initialize up front. This gets reset by SkCanvas before each draw call. 24310a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com fClip = &SkRegion::GetEmptyRegion(); 24320a0a236c3ba241046d38caaf78226ec68ff9c998reed@google.com} 24338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doIRect(const SkIRect& r) { 24358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect rr; 24368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return rr.intersect(fClip->getBounds(), r) && this->onIRect(rr); 24378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2439d055c1fde2128514167b315f4d104b177e04a3dereed@android.com// TODO: change the prototype to take fixed, and update the callers 2440d055c1fde2128514167b315f4d104b177e04a3dereed@android.combool SkBounder::doIRectGlyph(const SkIRect& r, int x, int y, 2441d055c1fde2128514167b315f4d104b177e04a3dereed@android.com const SkGlyph& glyph) { 2442474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com SkIRect rr; 2443d055c1fde2128514167b315f4d104b177e04a3dereed@android.com if (!rr.intersect(fClip->getBounds(), r)) { 2444d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return false; 2445d055c1fde2128514167b315f4d104b177e04a3dereed@android.com } 2446d055c1fde2128514167b315f4d104b177e04a3dereed@android.com GlyphRec rec; 2447d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.set(SkIntToFixed(x), SkIntToFixed(y)); 2448d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fRSB.set(rec.fLSB.fX + glyph.fAdvanceX, 2449d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fLSB.fY + glyph.fAdvanceY); 2450d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fGlyphID = glyph.getGlyphID(); 2451d055c1fde2128514167b315f4d104b177e04a3dereed@android.com rec.fFlags = 0; 2452d055c1fde2128514167b315f4d104b177e04a3dereed@android.com return this->onIRectGlyph(rr, rec); 2453474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com} 2454474a12c4976b3000174cad5df74c498cd723c5e2reed@android.com 24558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doHairline(const SkPoint& pt0, const SkPoint& pt1, 24568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPaint& paint) { 24578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar v0, v1; 24598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fX; 24618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fX; 24628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 24638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 24648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fLeft = SkScalarFloor(v0); 24668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fRight = SkScalarCeil(v1); 24678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v0 = pt0.fY; 24698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v1 = pt1.fY; 24708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (v0 > v1) { 24718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTSwap<SkScalar>(v0, v1); 24728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fTop = SkScalarFloor(v0); 24748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.fBottom = SkScalarCeil(v1); 24758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 24788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doRect(const SkRect& rect, const SkPaint& paint) { 24838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect r; 24848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.getStyle() == SkPaint::kFill_Style) { 24868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.round(&r); 24878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { 24888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int rad = -1; 24898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rect.roundOut(&r); 24908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 24918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rad = -2; 24928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(rad, rad); 24948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 24958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 24968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 24978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 24988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkBounder::doPath(const SkPath& path, const SkPaint& paint, bool doFill) { 2499d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkIRect r; 2500d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& bounds = path.getBounds(); 25018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (doFill) { 25038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.round(&r); 25048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } else { // hairline 25058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bounds.roundOut(&r); 25068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (paint.isAntiAlias()) { 25098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com r.inset(-1, -1); 25108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->doIRect(r); 25128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkBounder::commit() { 25158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override in subclass 25168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////////////////////// 25198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 25218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDraw.h" 25228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h" 25238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 25248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, 25268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 25278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect* bounds) { 25288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (devPath.isEmpty()) { 25298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint margin; 25338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com margin.set(0, 0); 25348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // init our bounds from the path 25368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2537d252db03d9650013b545ef9781fe993c07f8f314reed@android.com SkRect pathBounds = devPath.getBounds(); 25388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); 25398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pathBounds.roundOut(bounds); 25408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2541a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (filter) { 25438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(filterMatrix); 2544a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask srcM, dstM; 2546a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fBounds = *bounds; 25488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fFormat = SkMask::kA8_Format; 25498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com srcM.fImage = NULL; 25508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { 25518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *bounds = dstM.fBounds; 25548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (clipBounds && !SkIRect::Intersects(*clipBounds, *bounds)) { 25578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 25588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2559a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 25608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (possibly) trim the srcM bounds to reflect the clip 25618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // (plus whatever slop the filter needs) 25628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (clipBounds && !clipBounds->contains(*bounds)) { 25638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect tmp = *bounds; 25648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (void)tmp.intersect(*clipBounds); 25653555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // Ugh. Guard against gigantic margins from wacky filters. Without this 25663555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // check we can request arbitrary amounts of slop beyond our visible 25673555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // clip, and bring down the renderer (at least on finite RAM machines 25683555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // like handsets, etc.). Need to balance this invented value between 25693555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // quality of large filters like blurs, and the corresponding memory 25703555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com // requests. 25713555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com static const int MAX_MARGIN = 128; 25723555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), 25733555591c158c242b071c7ec92ad75b6e4cb74af2reed@android.com -SkMin32(margin.fY, MAX_MARGIN)); 25748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (void)bounds->intersect(tmp); 25758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 25768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 25788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 25798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic void draw_into_mask(const SkMask& mask, const SkPath& devPath) { 25818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap bm; 25828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDraw draw; 25838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion clipRgn; 25848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix matrix; 25858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint paint; 25868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height(), mask.fRowBytes); 25888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setPixels(mask.fImage); 25898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com clipRgn.setRect(0, 0, mask.fBounds.width(), mask.fBounds.height()); 25918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), 25928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com -SkIntToScalar(mask.fBounds.fTop)); 25938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 25948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBitmap = &bm; 25958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fClip = &clipRgn; 25968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fMatrix = &matrix; 25978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.fBounder = NULL; 25988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com paint.setAntiAlias(true); 25998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw.drawPath(devPath, paint); 26008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 26018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 26028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, 26038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMaskFilter* filter, const SkMatrix* filterMatrix, 26048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMask* mask, SkMask::CreateMode mode) { 26058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustRenderImage_CreateMode != mode) { 26068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds)) 26078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 26088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2609a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 26108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { 26118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fFormat = SkMask::kA8_Format; 26128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mask->fRowBytes = mask->fBounds.width(); 2613543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com size_t size = mask->computeImageSize(); 2614543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com if (0 == size) { 2615543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com // we're too big to allocate the mask, abort 2616543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com return false; 2617543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com } 2618543ed9352c7dfd93071c08b14930cca2e82a08d4reed@android.com mask->fImage = SkMask::AllocImage(size); 26198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com memset(mask->fImage, 0, mask->computeImageSize()); 26208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 26218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 26228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (SkMask::kJustComputeBounds_CreateMode != mode) { 26238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw_into_mask(*mask, devPath); 26248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2625a76de3d1a92134c3e95ad7fce99234f92fa48268reed@google.com 26268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 26278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2628