epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 8 | #include "SkSmallAllocator.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkSpriteBlitter.h" |
| 10 | |
reed | c240e71 | 2015-05-23 12:26:41 -0700 | [diff] [blame] | 11 | SkSpriteBlitter::SkSpriteBlitter(const SkPixmap& source) : fSource(source) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | |
reed | c240e71 | 2015-05-23 12:26:41 -0700 | [diff] [blame] | 13 | void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top, const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | fDevice = &device; |
| 15 | fLeft = left; |
| 16 | fTop = top; |
| 17 | fPaint = &paint; |
| 18 | } |
| 19 | |
| 20 | #ifdef SK_DEBUG |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 21 | void SkSpriteBlitter::blitH(int x, int y, int width) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 22 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | } |
| 24 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 25 | void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 26 | const int16_t runs[]) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 27 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | } |
| 29 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 30 | void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 31 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 34 | void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 35 | SkDEBUGFAIL("how did we get here?"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | } |
| 37 | #endif |
| 38 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 39 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | |
| 41 | // returning null means the caller will call SkBlitter::Choose() and |
| 42 | // have wrapped the source bitmap inside a shader |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 43 | SkBlitter* SkBlitter::ChooseSprite(const SkBitmap& device, const SkPaint& paint, |
reed | c240e71 | 2015-05-23 12:26:41 -0700 | [diff] [blame] | 44 | const SkPixmap& source, int left, int top, SkTBlitterAllocator* allocator) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | /* 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.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 54 | SkASSERT(allocator != NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | |
| 56 | SkSpriteBlitter* blitter; |
| 57 | |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 58 | switch (device.colorType()) { |
| 59 | case kRGB_565_SkColorType: |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 60 | blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator); |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 61 | break; |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 62 | case kN32_SkColorType: |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 63 | blitter = SkSpriteBlitter::ChooseD32(source, paint, allocator); |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 64 | break; |
| 65 | default: |
| 66 | blitter = NULL; |
| 67 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | } |
| 69 | |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 70 | if (blitter) { |
reed | c240e71 | 2015-05-23 12:26:41 -0700 | [diff] [blame] | 71 | blitter->setup(device, left, top, paint); |
mike@reedtribe.org | ebe5bcd | 2011-04-20 11:01:37 +0000 | [diff] [blame] | 72 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | return blitter; |
| 74 | } |