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