aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBlitter_Sprite.cpp
blob: f0da166ca847bed0540c26e78a06b4f74764e3af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* libs/graphics/sgl/SkBlitter_Sprite.cpp
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/

#include "SkSpriteBlitter.h"

SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
    : fSource(&source)
{
    fSource->lockPixels();
}

SkSpriteBlitter::~SkSpriteBlitter()
{
    fSource->unlockPixels();
}

void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
                            const SkPaint& paint)
{
    fDevice = &device;
    fLeft = left;
    fTop = top;
    fPaint = &paint;
}

#ifdef SK_DEBUG
void SkSpriteBlitter::blitH(int x, int y, int width)
{
    SkASSERT(!"how did we get here?");
}

void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[])
{
    SkASSERT(!"how did we get here?");
}

void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha)
{
    SkASSERT(!"how did we get here?");
}

void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip)
{
    SkASSERT(!"how did we get here?");
}
#endif

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

// returning null means the caller will call SkBlitter::Choose() and
// have wrapped the source bitmap inside a shader
SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
                                    const SkPaint& paint,
                                    const SkBitmap& source,
                                    int left, int top,
                                    void* storage, size_t storageSize)
{
    /*  We currently ignore antialiasing and filtertype, meaning we will take our
        special blitters regardless of these settings. Ignoring filtertype seems fine
        since by definition there is no scale in the matrix. Ignoring antialiasing is
        a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
        and respect that by blending the edges of the bitmap against the device. To support
        this we could either add more special blitters here, or detect antialiasing in the
        paint and return null if it is set, forcing the client to take the slow shader case
        (which does respect soft edges).
    */

    SkSpriteBlitter* blitter;

    switch (device.getConfig()) {
    case SkBitmap::kRGB_565_Config:
        blitter = SkSpriteBlitter::ChooseD16(source, paint, storage, storageSize);
        break;
    case SkBitmap::kARGB_8888_Config:
        blitter = SkSpriteBlitter::ChooseD32(source, paint, storage, storageSize);
        break;
    default:
        blitter = NULL;
        break;
    }

    if (blitter)
        blitter->setup(device, left, top, paint);
    return blitter;
}