SkBlitter_Sprite.cpp revision ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* libs/graphics/sgl/SkBlitter_Sprite.cpp
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com**
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Copyright 2006, The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com**
58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Licensed under the Apache License, Version 2.0 (the "License");
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** you may not use this file except in compliance with the License.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** You may obtain a copy of the License at
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com**
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com**     http://www.apache.org/licenses/LICENSE-2.0
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com**
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Unless required by applicable law or agreed to in writing, software
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** distributed under the License is distributed on an "AS IS" BASIS,
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** See the License for the specific language governing permissions and
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** limitations under the License.
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSpriteBlitter.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
21ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        : fSource(&source) {
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fSource->lockPixels();
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
25ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgSkSpriteBlitter::~SkSpriteBlitter() {
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fSource->unlockPixels();
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
30ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                            const SkPaint& paint) {
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fDevice = &device;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fLeft = left;
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fTop = top;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    fPaint = &paint;
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG
38ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitH(int x, int y, int width) {
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(!"how did we get here?");
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
42ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
43ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                                const int16_t runs[]) {
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(!"how did we get here?");
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
47ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(!"how did we get here?");
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
51ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.orgvoid SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkASSERT(!"how did we get here?");
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
56ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org///////////////////////////////////////////////////////////////////////////////
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// returning null means the caller will call SkBlitter::Choose() and
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// have wrapped the source bitmap inside a shader
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                    const SkPaint& paint,
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                    const SkBitmap& source,
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                                    int left, int top,
64ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                                    void* storage, size_t storageSize) {
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  We currently ignore antialiasing and filtertype, meaning we will take our
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        special blitters regardless of these settings. Ignoring filtertype seems fine
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        since by definition there is no scale in the matrix. Ignoring antialiasing is
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        and respect that by blending the edges of the bitmap against the device. To support
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this we could either add more special blitters here, or detect antialiasing in the
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint and return null if it is set, forcing the client to take the slow shader case
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (which does respect soft edges).
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkSpriteBlitter* blitter;
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    switch (device.getConfig()) {
78ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        case SkBitmap::kRGB_565_Config:
79ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            blitter = SkSpriteBlitter::ChooseD16(source, paint, storage,
80ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                                                 storageSize);
81ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
82ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        case SkBitmap::kARGB_8888_Config:
83ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            blitter = SkSpriteBlitter::ChooseD32(source, paint, storage,
84ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org                                                 storageSize);
85ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
86ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org        default:
87ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            blitter = NULL;
88ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org            break;
898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
91ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org    if (blitter) {
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        blitter->setup(device, left, top, paint);
93ebe5bcd7434666ffe3b56526b3d67e5ac4b17f60mike@reedtribe.org    }
948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return blitter;
958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
97