blob: 91a3cd1fee1c385acf1ad3ac8d497eb9486f7bab [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
11SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000012 : fSource(&source) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000013 fSource->lockPixels();
14}
15
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000016SkSpriteBlitter::~SkSpriteBlitter() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000017 fSource->unlockPixels();
18}
19
20void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000021 const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 fDevice = &device;
23 fLeft = left;
24 fTop = top;
25 fPaint = &paint;
26}
27
28#ifdef SK_DEBUG
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000029void SkSpriteBlitter::blitH(int x, int y, int width) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000030 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000031}
32
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000033void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
34 const int16_t runs[]) {
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
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000038void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000039 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000040}
41
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000042void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000043 SkDEBUGFAIL("how did we get here?");
reed@android.com8a1c16f2008-12-17 15:59:43 +000044}
45#endif
46
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000047///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
49// returning null means the caller will call SkBlitter::Choose() and
50// have wrapped the source bitmap inside a shader
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000051SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint,
52 const SkBitmap& source, int left, int top, SkTBlitterAllocator* allocator) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 /* We currently ignore antialiasing and filtertype, meaning we will take our
54 special blitters regardless of these settings. Ignoring filtertype seems fine
55 since by definition there is no scale in the matrix. Ignoring antialiasing is
56 a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
57 and respect that by blending the edges of the bitmap against the device. To support
58 this we could either add more special blitters here, or detect antialiasing in the
59 paint and return null if it is set, forcing the client to take the slow shader case
60 (which does respect soft edges).
61 */
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000062 SkASSERT(allocator != NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000063
64 SkSpriteBlitter* blitter;
65
reed@google.com900ecf22014-02-20 20:55:37 +000066 switch (device.colorType()) {
67 case kRGB_565_SkColorType:
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000068 blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000069 break;
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000070 case kN32_SkColorType:
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000071 blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000072 break;
73 default:
74 blitter = NULL;
75 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 }
77
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000078 if (blitter) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 blitter->setup(device, left, top, paint);
mike@reedtribe.orgebe5bcd2011-04-20 11:01:37 +000080 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 return blitter;
82}