Home | History | Annotate | Download | only in core
      1 /* libs/graphics/sgl/SkBlitter_Sprite.cpp
      2 **
      3 ** Copyright 2006, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #include "SkSpriteBlitter.h"
     19 
     20 SkSpriteBlitter::SkSpriteBlitter(const SkBitmap& source)
     21     : fSource(&source)
     22 {
     23     fSource->lockPixels();
     24 }
     25 
     26 SkSpriteBlitter::~SkSpriteBlitter()
     27 {
     28     fSource->unlockPixels();
     29 }
     30 
     31 void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
     32                             const SkPaint& paint)
     33 {
     34     fDevice = &device;
     35     fLeft = left;
     36     fTop = top;
     37     fPaint = &paint;
     38 }
     39 
     40 #ifdef SK_DEBUG
     41 void SkSpriteBlitter::blitH(int x, int y, int width)
     42 {
     43     SkASSERT(!"how did we get here?");
     44 }
     45 
     46 void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[])
     47 {
     48     SkASSERT(!"how did we get here?");
     49 }
     50 
     51 void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha)
     52 {
     53     SkASSERT(!"how did we get here?");
     54 }
     55 
     56 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip)
     57 {
     58     SkASSERT(!"how did we get here?");
     59 }
     60 #endif
     61 
     62 //////////////////////////////////////////////////////////////////////////////////////////////
     63 //////////////////////////////////////////////////////////////////////////////////////////////
     64 
     65 // returning null means the caller will call SkBlitter::Choose() and
     66 // have wrapped the source bitmap inside a shader
     67 SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
     68                                     const SkPaint& paint,
     69                                     const SkBitmap& source,
     70                                     int left, int top,
     71                                     void* storage, size_t storageSize)
     72 {
     73     /*  We currently ignore antialiasing and filtertype, meaning we will take our
     74         special blitters regardless of these settings. Ignoring filtertype seems fine
     75         since by definition there is no scale in the matrix. Ignoring antialiasing is
     76         a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
     77         and respect that by blending the edges of the bitmap against the device. To support
     78         this we could either add more special blitters here, or detect antialiasing in the
     79         paint and return null if it is set, forcing the client to take the slow shader case
     80         (which does respect soft edges).
     81     */
     82 
     83     SkSpriteBlitter* blitter;
     84 
     85     switch (device.getConfig()) {
     86     case SkBitmap::kRGB_565_Config:
     87         blitter = SkSpriteBlitter::ChooseD16(source, paint, storage, storageSize);
     88         break;
     89     case SkBitmap::kARGB_8888_Config:
     90         blitter = SkSpriteBlitter::ChooseD32(source, paint, storage, storageSize);
     91         break;
     92     default:
     93         blitter = NULL;
     94         break;
     95     }
     96 
     97     if (blitter)
     98         blitter->setup(device, left, top, paint);
     99     return blitter;
    100 }
    101 
    102