1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
8a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org#include "SkSmallAllocator.h"
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSpriteBlitter.h"
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
12ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        : fSource(&source) {
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fSource->lockPixels();
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgSkSpriteBlitter::~SkSpriteBlitter() {
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fSource->unlockPixels();
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
21ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                            const SkPaint& paint) {
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDevice = &device;
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fLeft = left;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fTop = top;
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fPaint = &paint;
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG
29ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitH(int x, int y, int width) {
300c00f21fee3f5cfa3aa7e5d46ff94cb8cf340451tomhudson@google.com    SkDEBUGFAIL("how did we get here?");
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
33ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
34ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                                const int16_t runs[]) {
350c00f21fee3f5cfa3aa7e5d46ff94cb8cf340451tomhudson@google.com    SkDEBUGFAIL("how did we get here?");
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
38ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
390c00f21fee3f5cfa3aa7e5d46ff94cb8cf340451tomhudson@google.com    SkDEBUGFAIL("how did we get here?");
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
42ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
430c00f21fee3f5cfa3aa7e5d46ff94cb8cf340451tomhudson@google.com    SkDEBUGFAIL("how did we get here?");
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
47ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org///////////////////////////////////////////////////////////////////////////////
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// returning null means the caller will call SkBlitter::Choose() and
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// have wrapped the source bitmap inside a shader
51a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.orgSkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint,
52a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org        const SkBitmap& source, int left, int top, SkTBlitterAllocator* allocator) {
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  We currently ignore antialiasing and filtertype, meaning we will take our
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        special blitters regardless of these settings. Ignoring filtertype seems fine
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        since by definition there is no scale in the matrix. Ignoring antialiasing is
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        and respect that by blending the edges of the bitmap against the device. To support
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this we could either add more special blitters here, or detect antialiasing in the
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint and return null if it is set, forcing the client to take the slow shader case
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (which does respect soft edges).
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
62a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org    SkASSERT(allocator != NULL);
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkSpriteBlitter* blitter;
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
66900ecf2f1579d42c9d2959831787af0346320f86reed@google.com    switch (device.colorType()) {
67900ecf2f1579d42c9d2959831787af0346320f86reed@google.com        case kRGB_565_SkColorType:
68a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org            blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
69ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
7028fcae2ec77eb16a79e155f8d788b20457f1c951commit-bot@chromium.org        case kN32_SkColorType:
71a5572e5bb2a2bbeeb59de0741c2527869d365a0ccommit-bot@chromium.org            blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator);
72ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
73ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        default:
74ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            blitter = NULL;
75ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
78ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org    if (blitter) {
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        blitter->setup(device, left, top, paint);
80ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org    }
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return blitter;
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
83