• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #include "SkSpriteBlitter.h"
11 
SkSpriteBlitter(const SkBitmap & source)12 SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
13         : fSource(&source) {
14     fSource->lockPixels();
15 }
16 
~SkSpriteBlitter()17 SkSpriteBlitter::~SkSpriteBlitter() {
18     fSource->unlockPixels();
19 }
20 
setup(const SkBitmap & device,int left,int top,const SkPaint & paint)21 void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
22                             const SkPaint& paint) {
23     fDevice = &device;
24     fLeft = left;
25     fTop = top;
26     fPaint = &paint;
27 }
28 
29 #ifdef SK_DEBUG
blitH(int x,int y,int width)30 void SkSpriteBlitter::blitH(int x, int y, int width) {
31     SkDEBUGFAIL("how did we get here?");
32 }
33 
blitAntiH(int x,int y,const SkAlpha antialias[],const int16_t runs[])34 void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
35                                 const int16_t runs[]) {
36     SkDEBUGFAIL("how did we get here?");
37 }
38 
blitV(int x,int y,int height,SkAlpha alpha)39 void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
40     SkDEBUGFAIL("how did we get here?");
41 }
42 
blitMask(const SkMask &,const SkIRect & clip)43 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
44     SkDEBUGFAIL("how did we get here?");
45 }
46 #endif
47 
48 ///////////////////////////////////////////////////////////////////////////////
49 
50 // returning null means the caller will call SkBlitter::Choose() and
51 // have wrapped the source bitmap inside a shader
ChooseSprite(const SkBitmap & device,const SkPaint & paint,const SkBitmap & source,int left,int top,void * storage,size_t storageSize)52 SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
53                                     const SkPaint& paint,
54                                     const SkBitmap& source,
55                                     int left, int top,
56                                     void* storage, size_t storageSize) {
57     /*  We currently ignore antialiasing and filtertype, meaning we will take our
58         special blitters regardless of these settings. Ignoring filtertype seems fine
59         since by definition there is no scale in the matrix. Ignoring antialiasing is
60         a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
61         and respect that by blending the edges of the bitmap against the device. To support
62         this we could either add more special blitters here, or detect antialiasing in the
63         paint and return null if it is set, forcing the client to take the slow shader case
64         (which does respect soft edges).
65     */
66 
67     SkSpriteBlitter* blitter;
68 
69     switch (device.getConfig()) {
70         case SkBitmap::kRGB_565_Config:
71             blitter = SkSpriteBlitter::ChooseD16(source, paint, storage,
72                                                  storageSize);
73             break;
74         case SkBitmap::kARGB_8888_Config:
75             blitter = SkSpriteBlitter::ChooseD32(source, paint, storage,
76                                                  storageSize);
77             break;
78         default:
79             blitter = NULL;
80             break;
81     }
82 
83     if (blitter) {
84         blitter->setup(device, left, top, paint);
85     }
86     return blitter;
87 }
88 
89