SkBitmapDevice.cpp revision 848250415eddc54075f7eb8795e8db79e749c6ab
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 {
85848250415eddc54075f7eb8795e8db79e749c6abreed        if (!bitmap.tryAllocPixels(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
1359c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.comvoid* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) {
1369c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    if (fBitmap.getPixels()) {
1379c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com        *info = fBitmap.info();
1389c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com        *rowBytes = fBitmap.rowBytes();
1399c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com        return fBitmap.getPixels();
1409c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    }
1419c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com    return NULL;
1429c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com}
1439c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com
144231f6b81c22001cac4ea87ea412c4d6fd10ffb8acommit-bot@chromium.org#include "SkConfig8888.h"
1457111d463cee893a479280c7af41757e709e33ef5reed@google.com
1464cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.orgbool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels,
1474cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org                                   size_t srcRowBytes, int x, int y) {
1480d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com    // since we don't stop creating un-pixeled devices yet, check for no pixels here
1490d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com    if (NULL == fBitmap.getPixels()) {
1500d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com        return false;
1510d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com    }
1520d30c51c6cf45b3a08a3000b6d348c16bdec7f05reed@google.com
1534cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    SkImageInfo dstInfo = fBitmap.info();
1544cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    dstInfo.fWidth = srcInfo.width();
1554cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    dstInfo.fHeight = srcInfo.height();
1564cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
1574cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    void* dstPixels = fBitmap.getAddr(x, y);
1584cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    size_t dstRowBytes = fBitmap.rowBytes();
1594cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org
160b184f7f52b2a94e95aee326a3ca37110d2e43336reed    if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) {
1614cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org        fBitmap.notifyPixelsChanged();
1624cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org        return true;
1634cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    }
1644cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org    return false;
1654cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org}
16653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
167a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.orgbool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
168a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org                                  int x, int y) {
169b184f7f52b2a94e95aee326a3ca37110d2e43336reed    return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y);
170a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org}
171a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org
17253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com///////////////////////////////////////////////////////////////////////////////
17353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
17453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
17553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawPaint(paint);
17653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
17753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
17853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count,
17953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                const SkPoint pts[], const SkPaint& paint) {
1804469938e92d779dff05e745559e67907bbf21e78reed@google.com    CHECK_FOR_ANNOTATION(paint);
18153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawPoints(mode, count, pts, paint);
18253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
18353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
18453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) {
1854469938e92d779dff05e745559e67907bbf21e78reed@google.com    CHECK_FOR_ANNOTATION(paint);
18653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawRect(r, paint);
18753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
18853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
18953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
1904469938e92d779dff05e745559e67907bbf21e78reed@google.com    CHECK_FOR_ANNOTATION(paint);
19153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
19253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkPath path;
19353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    path.addOval(oval);
19453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
19553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // required to override drawOval.
19653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    this->drawPath(draw, path, paint, NULL, true);
19753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
19853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
19953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) {
2004469938e92d779dff05e745559e67907bbf21e78reed@google.com    CHECK_FOR_ANNOTATION(paint);
20153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
20250a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#ifdef SK_IGNORE_BLURRED_RRECT_OPT
20350a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com    SkPath  path;
20450a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com
20550a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com    path.addRRect(rrect);
20650a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com    // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
20750a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com    // required to override drawRRect.
20850a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com    this->drawPath(draw, path, paint, NULL, true);
20950a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#else
210a8e33a92e27ca1523601226cad83c79a7e00c93bscroggo@google.com    draw.drawRRect(rrect, paint);
21150a7600d05d427c64f77d39c8c18d2bf6cabd25brobertphillips@google.com#endif
21253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
21353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
21453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path,
21553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                              const SkPaint& paint, const SkMatrix* prePathMatrix,
21653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                              bool pathIsMutable) {
2174469938e92d779dff05e745559e67907bbf21e78reed@google.com    CHECK_FOR_ANNOTATION(paint);
21853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawPath(path, paint, prePathMatrix, pathIsMutable);
21953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
22053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
22153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
22253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                const SkMatrix& matrix, const SkPaint& paint) {
22353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawBitmap(bitmap, matrix, paint);
22453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
22553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
22653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
22753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    const SkRect* src, const SkRect& dst,
22853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    const SkPaint& paint,
22953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    SkCanvas::DrawBitmapRectFlags flags) {
23053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkMatrix    matrix;
23153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkRect      bitmapBounds, tmpSrc, tmpDst;
23253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkBitmap    tmpBitmap;
23353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
23453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    bitmapBounds.isetWH(bitmap.width(), bitmap.height());
23553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
23653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // Compute matrix from the two rectangles
23753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    if (src) {
23853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        tmpSrc = *src;
23953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    } else {
24053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        tmpSrc = bitmapBounds;
24153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    }
24253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
24353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
24453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    const SkRect* dstPtr = &dst;
24553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    const SkBitmap* bitmapPtr = &bitmap;
24653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
24753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if
24853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // needed (if the src was clipped). No check needed if src==null.
24953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    if (src) {
25053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (!bitmapBounds.contains(*src)) {
25153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            if (!tmpSrc.intersect(bitmapBounds)) {
25253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                return; // nothing to draw
25353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            }
25453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            // recompute dst, based on the smaller tmpSrc
25553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            matrix.mapRect(&tmpDst, tmpSrc);
25653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            dstPtr = &tmpDst;
25753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
25853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
25953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // since we may need to clamp to the borders of the src rect within
26053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // the bitmap, we extract a subset.
26153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        SkIRect srcIR;
26253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        tmpSrc.roundOut(&srcIR);
26353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (!bitmap.extractSubset(&tmpBitmap, srcIR)) {
26453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            return;
26553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
26653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        bitmapPtr = &tmpBitmap;
26753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
26853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // Since we did an extract, we need to adjust the matrix accordingly
26953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        SkScalar dx = 0, dy = 0;
27053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (srcIR.fLeft > 0) {
27153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            dx = SkIntToScalar(srcIR.fLeft);
27253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
27353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (srcIR.fTop > 0) {
27453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            dy = SkIntToScalar(srcIR.fTop);
27553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
27653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (dx || dy) {
27753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            matrix.preTranslate(dx, dy);
27853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
27953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
28053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        SkRect extractedBitmapBounds;
28153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height());
28253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        if (extractedBitmapBounds == tmpSrc) {
28353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            // no fractional part in src, we can just call drawBitmap
28453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com            goto USE_DRAWBITMAP;
28553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        }
28653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    } else {
28753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        USE_DRAWBITMAP:
28853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // We can go faster by just calling drawBitmap, which will concat the
28953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // matrix with the CTM, and try to call drawSprite if it can. If not,
29053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // it will make a shader and call drawRect, as we do below.
29153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        this->drawBitmap(draw, *bitmapPtr, matrix, paint);
29253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        return;
29353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    }
29453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
29553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // construct a shader, so we can call drawRect with the dst
29653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr,
29753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                               SkShader::kClamp_TileMode,
2989c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org                                               SkShader::kClamp_TileMode,
2999c9005a347e9996f357bd79591bd34f74f8bbc66commit-bot@chromium.org                                               &matrix);
30053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    if (NULL == s) {
30153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        return;
30253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    }
30353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
30453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    SkPaint paintWithShader(paint);
30553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    paintWithShader.setStyle(SkPaint::kFill_Style);
30653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    paintWithShader.setShader(s)->unref();
30753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
30853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // Call ourself, in case the subclass wanted to share this setup code
30953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // but handle the drawRect code themselves.
31053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    this->drawRect(draw, *dstPtr, paintWithShader);
31153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
31253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
31353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
31453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                int x, int y, const SkPaint& paint) {
31553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawSprite(bitmap, x, y, paint);
31653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
31753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
31853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len,
31953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                              SkScalar x, SkScalar y, const SkPaint& paint) {
32053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawText((const char*)text, len, x, y, paint);
32153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
32253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
32353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
32453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                 const SkScalar xpos[], SkScalar y,
32553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                 int scalarsPerPos, const SkPaint& paint) {
32653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint);
32753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
32853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
32953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text,
33053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    size_t len, const SkPath& path,
33153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    const SkMatrix* matrix,
33253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                    const SkPaint& paint) {
33353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawTextOnPath((const char*)text, len, path, matrix, paint);
33453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
33553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
33653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
33753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                  int vertexCount,
33853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                  const SkPoint verts[], const SkPoint textures[],
33953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                  const SkColor colors[], SkXfermode* xmode,
34053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                  const uint16_t indices[], int indexCount,
34153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                  const SkPaint& paint) {
34253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode,
34353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                      indices, indexCount, paint);
34453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
34553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
34653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.comvoid SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
34753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com                                int x, int y, const SkPaint& paint) {
34853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    const SkBitmap& src = device->accessBitmap(false);
34953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    draw.drawSprite(src, x, y, paint);
35053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
35153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
35276f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.comSkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info) {
35376f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com    return SkSurface::NewRaster(info);
35476f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com}
35576f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com
356c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.orgconst void* SkBitmapDevice::peekPixels(SkImageInfo* info, size_t* rowBytes) {
357466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org    const SkImageInfo bmInfo = fBitmap.info();
358466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org    if (fBitmap.getPixels() && (kUnknown_SkColorType != bmInfo.colorType())) {
359466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org        if (info) {
360466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org            *info = bmInfo;
361466f5f3e44e703ca58b43ac1c4ac3bfa0e1ff024commit-bot@chromium.org        }
362c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org        if (rowBytes) {
363c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org            *rowBytes = fBitmap.rowBytes();
364c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org        }
365c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org        return fBitmap.getPixels();
366c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    }
367c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org    return NULL;
368c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org}
369c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org
370be129b26f13d575fd6b396c6ae759838ecc9bd1asenorblancoSkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() {
371be129b26f13d575fd6b396c6ae759838ecc9bd1asenorblanco    SkImageFilter::Cache* cache = SkImageFilter::Cache::Get();
37255b6d8be997a447ef9ce0f029697677a940bfc24senorblanco    cache->ref();
37355b6d8be997a447ef9ce0f029697677a940bfc24senorblanco    return cache;
37455b6d8be997a447ef9ce0f029697677a940bfc24senorblanco}
37555b6d8be997a447ef9ce0f029697677a940bfc24senorblanco
37653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com///////////////////////////////////////////////////////////////////////////////
37753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
37853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.combool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
37953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    if (!paint.isLCDRenderText() || !paint.isAntiAlias()) {
38053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // we're cool with the paint as is
38153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        return false;
38253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    }
38353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com
384cba73780bbd12fd254229517aec04fcbf0b64b52commit-bot@chromium.org    if (kN32_SkColorType != fBitmap.colorType() ||
38553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        paint.getRasterizer() ||
38653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        paint.getPathEffect() ||
38753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        paint.isFakeBoldText() ||
38853238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        paint.getStyle() != SkPaint::kFill_Style ||
38953238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
39053238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        // turn off lcd
39153238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
39253238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        flags->fHinting = paint.getHinting();
39353238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com        return true;
39453238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    }
39553238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    // we're cool with the paint as is
39653238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com    return false;
39753238bc96051d1774b7f72d3ebfd35a7dd4c04dfrobertphillips@google.com}
398