153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com/* 253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com * Copyright 2013 Google Inc. 353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com * 453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com * found in the LICENSE file. 653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com */ 753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com#include "SkBitmapDevice.h" 953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com#include "SkConfig8888.h" 1053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com#include "SkDraw.h" 1153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com#include "SkRasterClip.h" 1253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com#include "SkShader.h" 1376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com#include "SkSurface.h" 1453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 154469938e92d779dff05e745559e67907bbf21e78reed@google.com#define CHECK_FOR_ANNOTATION(paint) \ 164469938e92d779dff05e745559e67907bbf21e78reed@google.com do { if (paint.getAnnotation()) { return; } } while (0) 1753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 1815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.orgstatic bool valid_for_bitmap_device(const SkImageInfo& info, 1915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkAlphaType* newAlphaType) { 2015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (info.width() < 0 || info.height() < 0) { 2115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return false; 2215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 2315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 2415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org // TODO: can we stop supporting kUnknown in SkBitmkapDevice? 2515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (kUnknown_SkColorType == info.colorType()) { 2615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (newAlphaType) { 2715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org *newAlphaType = kIgnore_SkAlphaType; 2815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 2915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return true; 3015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 31969588f0c9030d5a4942085a4b5a5ea7e8d2bc25skia.committer@gmail.com 3215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org switch (info.alphaType()) { 3315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org case kPremul_SkAlphaType: 3415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org case kOpaque_SkAlphaType: 3515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org break; 3615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org default: 3715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return false; 3815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 3915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 4015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkAlphaType canonicalAlphaType = info.alphaType(); 4115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 4215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org switch (info.colorType()) { 4315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org case kAlpha_8_SkColorType: 4415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org break; 4515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org case kRGB_565_SkColorType: 4615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org canonicalAlphaType = kOpaque_SkAlphaType; 4715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org break; 4828fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org case kN32_SkColorType: 4915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org break; 5015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org default: 5115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return false; 5215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 5315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 5415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (newAlphaType) { 5515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org *newAlphaType = canonicalAlphaType; 5615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 5715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return true; 5815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org} 5915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 6015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.orgSkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) { 6115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); 6253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 6353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 6453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comSkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) 6553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com : SkBaseDevice(deviceProperties) 6615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org , fBitmap(bitmap) 6715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org{ 6815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); 6953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 7053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 7115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.orgSkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, 7215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org const SkDeviceProperties* props) { 7315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkImageInfo info = origInfo; 7415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (!valid_for_bitmap_device(info, &info.fAlphaType)) { 7515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return NULL; 7615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 7715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 7815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org SkBitmap bitmap; 7915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org 8015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (kUnknown_SkColorType == info.colorType()) { 81a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org if (!bitmap.setInfo(info)) { 8215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return NULL; 8315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 8415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } else { 8515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (!bitmap.allocPixels(info)) { 8615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return NULL; 8715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 8815a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (!bitmap.info().isOpaque()) { 8915a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org bitmap.eraseColor(SK_ColorTRANSPARENT); 9015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 9115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 9253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 9315a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org if (props) { 9415a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props)); 9515a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } else { 9615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return SkNEW_ARGS(SkBitmapDevice, (bitmap)); 9715a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org } 9853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 9953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 100c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgSkImageInfo SkBitmapDevice::imageInfo() const { 101c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org return fBitmap.info(); 102c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org} 103c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 10453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { 10553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkASSERT(bm.width() == fBitmap.width()); 10653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkASSERT(bm.height() == fBitmap.height()); 10753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) 10853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com fBitmap.lockPixels(); 10953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 11053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 11115a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.orgSkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usage) { 11215a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org return SkBitmapDevice::Create(info, &this->getDeviceProperties()); 11353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 11453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 11553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::lockPixels() { 11653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (fBitmap.lockPixelsAreWritable()) { 11753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com fBitmap.lockPixels(); 11853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 11953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 12053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 12153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::unlockPixels() { 12253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (fBitmap.lockPixelsAreWritable()) { 12353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com fBitmap.unlockPixels(); 12453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 12553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 12653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 12753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::clear(SkColor color) { 12853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com fBitmap.eraseColor(color); 12953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 13053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 13153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comconst SkBitmap& SkBitmapDevice::onAccessBitmap() { 13253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return fBitmap; 13353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 13453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 135ae761f7545d8ebf181d220169afac2056b057b8ccommit-bot@chromium.orgbool SkBitmapDevice::canHandleImageFilter(const SkImageFilter*) { 13653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return false; 13753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 13853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 139ae761f7545d8ebf181d220169afac2056b057b8ccommit-bot@chromium.orgbool SkBitmapDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, 1404cb543d6057b692e1099e9f115155f0bf323a0c8senorblanco@chromium.org const SkImageFilter::Context& ctx, SkBitmap* result, 14153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkIPoint* offset) { 14253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return false; 14353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 14453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 145ae761f7545d8ebf181d220169afac2056b057b8ccommit-bot@chromium.orgbool SkBitmapDevice::allowImageFilter(const SkImageFilter*) { 14653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return true; 14753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 14853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 1499c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comvoid* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { 1509c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com if (fBitmap.getPixels()) { 1519c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com *info = fBitmap.info(); 1529c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com *rowBytes = fBitmap.rowBytes(); 1539c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com return fBitmap.getPixels(); 1549c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com } 1559c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com return NULL; 1569c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com} 1579c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com 1584cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.orgstatic void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, 1594cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org int rowCount) { 1604cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org SkASSERT(bytesPerRow <= srcRB); 1614cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org SkASSERT(bytesPerRow <= dstRB); 1624cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org for (int i = 0; i < rowCount; ++i) { 1634cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org memcpy(dst, src, bytesPerRow); 1644cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org dst = (char*)dst + dstRB; 1654cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org src = (const char*)src + srcRB; 1664cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 1674cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org} 1684cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 169231f6b81c22001cac4ea87ea412c4d6fd10ffb8acommit-bot@chromium.org#include "SkConfig8888.h" 1707111d463cee893a479280c7af41757e709e33ef5reed@google.com 171a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.orgstatic bool copy_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 172a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes) { 1734cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org if (srcInfo.dimensions() != dstInfo.dimensions()) { 1744cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return false; 1754cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 1764cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) { 1777111d463cee893a479280c7af41757e709e33ef5reed@google.com SkDstPixelInfo dstPI; 1787111d463cee893a479280c7af41757e709e33ef5reed@google.com dstPI.fColorType = dstInfo.colorType(); 1797111d463cee893a479280c7af41757e709e33ef5reed@google.com dstPI.fAlphaType = dstInfo.alphaType(); 1807111d463cee893a479280c7af41757e709e33ef5reed@google.com dstPI.fPixels = dstPixels; 1817111d463cee893a479280c7af41757e709e33ef5reed@google.com dstPI.fRowBytes = dstRowBytes; 1827111d463cee893a479280c7af41757e709e33ef5reed@google.com 1837111d463cee893a479280c7af41757e709e33ef5reed@google.com SkSrcPixelInfo srcPI; 1847111d463cee893a479280c7af41757e709e33ef5reed@google.com srcPI.fColorType = srcInfo.colorType(); 1857111d463cee893a479280c7af41757e709e33ef5reed@google.com srcPI.fAlphaType = srcInfo.alphaType(); 1867111d463cee893a479280c7af41757e709e33ef5reed@google.com srcPI.fPixels = srcPixels; 1877111d463cee893a479280c7af41757e709e33ef5reed@google.com srcPI.fRowBytes = srcRowBytes; 1887111d463cee893a479280c7af41757e709e33ef5reed@google.com 1897111d463cee893a479280c7af41757e709e33ef5reed@google.com return srcPI.convertPixelsTo(&dstPI, srcInfo.width(), srcInfo.height()); 1904cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 1914cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org if (srcInfo.colorType() == dstInfo.colorType()) { 1924cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org switch (srcInfo.colorType()) { 1934cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org case kRGB_565_SkColorType: 1944cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org case kAlpha_8_SkColorType: 1954cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org break; 1964cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org case kARGB_4444_SkColorType: 1974cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org if (srcInfo.alphaType() != dstInfo.alphaType()) { 1984cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return false; 1994cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 2004cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org break; 2014cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org default: 2024cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return false; 2034cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 2044cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes, 2054cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()); 2064cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 2074cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org // TODO: add support for more conversions as needed 2084cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return false; 2094cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org} 2104cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 2114cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.orgbool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, 2124cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org size_t srcRowBytes, int x, int y) { 2130d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com // since we don't stop creating un-pixeled devices yet, check for no pixels here 2140d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com if (NULL == fBitmap.getPixels()) { 2150d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com return false; 2160d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com } 2170d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com 2184cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org SkImageInfo dstInfo = fBitmap.info(); 2194cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org dstInfo.fWidth = srcInfo.width(); 2204cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org dstInfo.fHeight = srcInfo.height(); 2214cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 2224cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org void* dstPixels = fBitmap.getAddr(x, y); 2234cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org size_t dstRowBytes = fBitmap.rowBytes(); 2244cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org 225a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) { 2264cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org fBitmap.notifyPixelsChanged(); 2274cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return true; 2284cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org } 2294cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org return false; 2304cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org} 23153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 232a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.orgbool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, 233a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org int x, int y) { 234a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org // since we don't stop creating un-pixeled devices yet, check for no pixels here 235a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org if (NULL == fBitmap.getPixels()) { 236a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org return false; 237a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org } 238db0c8753775774aa3f67114491e26ac1be32f38eskia.committer@gmail.com 239a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org SkImageInfo srcInfo = fBitmap.info(); 240a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 241a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org // perhaps can relax these in the future 242a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org if (4 != dstInfo.bytesPerPixel()) { 243a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org return false; 244a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org } 245a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org if (4 != srcInfo.bytesPerPixel()) { 246a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org return false; 247a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org } 248a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 249a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org srcInfo.fWidth = dstInfo.width(); 250a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org srcInfo.fHeight = dstInfo.height(); 251db0c8753775774aa3f67114491e26ac1be32f38eskia.committer@gmail.com 252a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org const void* srcPixels = fBitmap.getAddr(x, y); 253a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org const size_t srcRowBytes = fBitmap.rowBytes(); 254a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 255a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org return copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes); 256a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org} 257a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org 25853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com/////////////////////////////////////////////////////////////////////////////// 25953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 26053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 26153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawPaint(paint); 26253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 26353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 26453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, 26553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPoint pts[], const SkPaint& paint) { 2664469938e92d779dff05e745559e67907bbf21e78reed@google.com CHECK_FOR_ANNOTATION(paint); 26753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawPoints(mode, count, pts, paint); 26853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 26953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 27053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { 2714469938e92d779dff05e745559e67907bbf21e78reed@google.com CHECK_FOR_ANNOTATION(paint); 27253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawRect(r, paint); 27353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 27453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 27553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { 2764469938e92d779dff05e745559e67907bbf21e78reed@google.com CHECK_FOR_ANNOTATION(paint); 27753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 27853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkPath path; 27953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com path.addOval(oval); 28053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 28153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // required to override drawOval. 28253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com this->drawPath(draw, path, paint, NULL, true); 28353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 28453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 28553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { 2864469938e92d779dff05e745559e67907bbf21e78reed@google.com CHECK_FOR_ANNOTATION(paint); 28753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 28850a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#ifdef SK_IGNORE_BLURRED_RRECT_OPT 28950a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com SkPath path; 29050a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com 29150a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com path.addRRect(rrect); 29250a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 29350a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com // required to override drawRRect. 29450a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com this->drawPath(draw, path, paint, NULL, true); 29550a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#else 296a8e33a92e27ca1523601226cad83c79a7e00c93bscroggo@google.com draw.drawRRect(rrect, paint); 29750a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#endif 29853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 29953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 30053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, 30153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPaint& paint, const SkMatrix* prePathMatrix, 30253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com bool pathIsMutable) { 3034469938e92d779dff05e745559e67907bbf21e78reed@google.com CHECK_FOR_ANNOTATION(paint); 30453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawPath(path, paint, prePathMatrix, pathIsMutable); 30553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 30653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 30753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, 30853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkMatrix& matrix, const SkPaint& paint) { 30953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawBitmap(bitmap, matrix, paint); 31053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 31153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 31253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, 31353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkRect* src, const SkRect& dst, 31453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPaint& paint, 31553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkCanvas::DrawBitmapRectFlags flags) { 31653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkMatrix matrix; 31753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkRect bitmapBounds, tmpSrc, tmpDst; 31853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkBitmap tmpBitmap; 31953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 32053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com bitmapBounds.isetWH(bitmap.width(), bitmap.height()); 32153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 32253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // Compute matrix from the two rectangles 32353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (src) { 32453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com tmpSrc = *src; 32553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } else { 32653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com tmpSrc = bitmapBounds; 32753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 32853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); 32953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 33053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkRect* dstPtr = &dst; 33153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkBitmap* bitmapPtr = &bitmap; 33253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 33353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if 33453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // needed (if the src was clipped). No check needed if src==null. 33553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (src) { 33653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (!bitmapBounds.contains(*src)) { 33753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (!tmpSrc.intersect(bitmapBounds)) { 33853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return; // nothing to draw 33953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 34053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // recompute dst, based on the smaller tmpSrc 34153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com matrix.mapRect(&tmpDst, tmpSrc); 34253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com dstPtr = &tmpDst; 34353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 34453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 34553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // since we may need to clamp to the borders of the src rect within 34653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // the bitmap, we extract a subset. 34753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkIRect srcIR; 34853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com tmpSrc.roundOut(&srcIR); 34953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { 35053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return; 35153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 35253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com bitmapPtr = &tmpBitmap; 35353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 35453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // Since we did an extract, we need to adjust the matrix accordingly 35553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkScalar dx = 0, dy = 0; 35653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (srcIR.fLeft > 0) { 35753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com dx = SkIntToScalar(srcIR.fLeft); 35853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 35953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (srcIR.fTop > 0) { 36053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com dy = SkIntToScalar(srcIR.fTop); 36153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 36253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (dx || dy) { 36353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com matrix.preTranslate(dx, dy); 36453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 36553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 36653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkRect extractedBitmapBounds; 36753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); 36853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (extractedBitmapBounds == tmpSrc) { 36953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // no fractional part in src, we can just call drawBitmap 37053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com goto USE_DRAWBITMAP; 37153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 37253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } else { 37353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com USE_DRAWBITMAP: 37453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // We can go faster by just calling drawBitmap, which will concat the 37553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // matrix with the CTM, and try to call drawSprite if it can. If not, 37653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // it will make a shader and call drawRect, as we do below. 37753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com this->drawBitmap(draw, *bitmapPtr, matrix, paint); 37853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return; 37953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 38053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 38153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // construct a shader, so we can call drawRect with the dst 38253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, 38353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkShader::kClamp_TileMode, 3849c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org SkShader::kClamp_TileMode, 3859c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org &matrix); 38653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (NULL == s) { 38753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return; 38853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 38953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 39053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkPaint paintWithShader(paint); 39153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paintWithShader.setStyle(SkPaint::kFill_Style); 39253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paintWithShader.setShader(s)->unref(); 39353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 39453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // Call ourself, in case the subclass wanted to share this setup code 39553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // but handle the drawRect code themselves. 39653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com this->drawRect(draw, *dstPtr, paintWithShader); 39753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 39853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 39953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 40053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com int x, int y, const SkPaint& paint) { 40153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawSprite(bitmap, x, y, paint); 40253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 40353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 40453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, 40553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com SkScalar x, SkScalar y, const SkPaint& paint) { 40653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawText((const char*)text, len, x, y, paint); 40753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 40853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 40953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, 41053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkScalar xpos[], SkScalar y, 41153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com int scalarsPerPos, const SkPaint& paint) { 41253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); 41353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 41453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 41553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, 41653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com size_t len, const SkPath& path, 41753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkMatrix* matrix, 41853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPaint& paint) { 41953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawTextOnPath((const char*)text, len, path, matrix, paint); 42053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 42153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 42253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, 42353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com int vertexCount, 42453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPoint verts[], const SkPoint textures[], 42553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkColor colors[], SkXfermode* xmode, 42653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const uint16_t indices[], int indexCount, 42753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkPaint& paint) { 42853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, 42953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com indices, indexCount, paint); 43053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 43153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 43253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, 43353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com int x, int y, const SkPaint& paint) { 43453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com const SkBitmap& src = device->accessBitmap(false); 43553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com draw.drawSprite(src, x, y, paint); 43653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 43753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 43876f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comSkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info) { 43976f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com return SkSurface::NewRaster(info); 44076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com} 44176f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com 442c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgconst void* SkBitmapDevice::peekPixels(SkImageInfo* info, size_t* rowBytes) { 443466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org const SkImageInfo bmInfo = fBitmap.info(); 444466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org if (fBitmap.getPixels() && (kUnknown_SkColorType != bmInfo.colorType())) { 445466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org if (info) { 446466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org *info = bmInfo; 447466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org } 448c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org if (rowBytes) { 449c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org *rowBytes = fBitmap.rowBytes(); 450c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org } 451c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org return fBitmap.getPixels(); 452c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org } 453c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org return NULL; 454c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org} 455c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 45653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com/////////////////////////////////////////////////////////////////////////////// 45753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 45853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.combool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { 45953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { 46053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // we're cool with the paint as is 46153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return false; 46253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 46353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com 464cba73780bbd12fd254229517aec04fcbf0b64b52commit-bot@chromium.org if (kN32_SkColorType != fBitmap.colorType() || 46553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paint.getRasterizer() || 46653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paint.getPathEffect() || 46753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paint.isFakeBoldText() || 46853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com paint.getStyle() != SkPaint::kFill_Style || 46953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 47053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // turn off lcd 47153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 47253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com flags->fHinting = paint.getHinting(); 47353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return true; 47453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com } 47553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com // we're cool with the paint as is 47653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com return false; 47753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com} 478