blob: 46cd0a8e671383d03a2a19caff0b0f27af9a58ab [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +00008#include "SkSmallAllocator.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkSpriteBlitter.h"
10
reedc240e712015-05-23 12:26:41 -070011SkSpriteBlitter::SkSpriteBlitter(const SkPixmap& source) : fSource(source) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000012
reedc240e712015-05-23 12:26:41 -070013void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000014 fDevice = &device;
15 fLeft = left;
16 fTop = top;
17 fPaint = &paint;
18}
19
20#ifdef SK_DEBUG
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000021void SkSpriteBlitter::blitH(int x, int y, int width) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000022 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000023}
24
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000025void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
26 const int16_t runs[]) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000027 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000028}
29
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000030void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000031 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000032}
33
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000034void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000035 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000036}
37#endif
38
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000039///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000040
41// returning null means the caller will call SkBlitter::Choose() and
42// have wrapped the source bitmap inside a shader
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000043SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint,
reedc240e712015-05-23 12:26:41 -070044 const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocator) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 /* We currently ignore antialiasing and filtertype, meaning we will take our
46 special blitters regardless of these settings. Ignoring filtertype seems fine
47 since by definition there is no scale in the matrix. Ignoring antialiasing is
48 a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
49 and respect that by blending the edges of the bitmap against the device. To support
50 this we could either add more special blitters here, or detect antialiasing in the
51 paint and return null if it is set, forcing the client to take the slow shader case
52 (which does respect soft edges).
53 */
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000054 SkASSERT(allocator != NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000055
56 SkSpriteBlitter* blitter;
57
reed@google.com900ecf22014-02-20 20:55:37 +000058 switch (device.colorType()) {
59 case kRGB_565_SkColorType:
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000060 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000061 break;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000062 case kN32_SkColorType:
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000063 blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000064 break;
65 default:
66 blitter = NULL;
67 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 }
69
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000070 if (blitter) {
reedc240e712015-05-23 12:26:41 -070071 blitter->setup(device, left, top, paint);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000072 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 return blitter;
74}