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     fSource->lockPixels();
     23 }
     24 
     25 SkSpriteBlitter::~SkSpriteBlitter() {
     26     fSource->unlockPixels();
     27 }
     28 
     29 void SkSpriteBlitter::setup(const SkBitmap& device, int left, int top,
     30                             const SkPaint& paint) {
     31     fDevice = &device;
     32     fLeft = left;
     33     fTop = top;
     34     fPaint = &paint;
     35 }
     36 
     37 #ifdef SK_DEBUG
     38 void SkSpriteBlitter::blitH(int x, int y, int width) {
     39     SkASSERT(!"how did we get here?");
     40 }
     41 
     42 void SkSpriteBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
     43                                 const int16_t runs[]) {
     44     SkASSERT(!"how did we get here?");
     45 }
     46 
     47 void SkSpriteBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
     48     SkASSERT(!"how did we get here?");
     49 }
     50 
     51 void SkSpriteBlitter::blitMask(const SkMask&, const SkIRect& clip) {
     52     SkASSERT(!"how did we get here?");
     53 }
     54 #endif
     55 
     56 ///////////////////////////////////////////////////////////////////////////////
     57 
     58 // returning null means the caller will call SkBlitter::Choose() and
     59 // have wrapped the source bitmap inside a shader
     60 SkBlitter* SkBlitter::ChooseSprite( const SkBitmap& device,
     61                                     const SkPaint& paint,
     62                                     const SkBitmap& source,
     63                                     int left, int top,
     64                                     void* storage, size_t storageSize) {
     65     /*  We currently ignore antialiasing and filtertype, meaning we will take our
     66         special blitters regardless of these settings. Ignoring filtertype seems fine
     67         since by definition there is no scale in the matrix. Ignoring antialiasing is
     68         a bit of a hack, since we "could" pass in the fractional left/top for the bitmap,
     69         and respect that by blending the edges of the bitmap against the device. To support
     70         this we could either add more special blitters here, or detect antialiasing in the
     71         paint and return null if it is set, forcing the client to take the slow shader case
     72         (which does respect soft edges).
     73     */
     74 
     75     SkSpriteBlitter* blitter;
     76 
     77     switch (device.getConfig()) {
     78         case SkBitmap::kRGB_565_Config:
     79             blitter = SkSpriteBlitter::ChooseD16(source, paint, storage,
     80                                                  storageSize);
     81             break;
     82         case SkBitmap::kARGB_8888_Config:
     83             blitter = SkSpriteBlitter::ChooseD32(source, paint, storage,
     84                                                  storageSize);
     85             break;
     86         default:
     87             blitter = NULL;
     88             break;
     89     }
     90 
     91     if (blitter) {
     92         blitter->setup(device, left, top, paint);
     93     }
     94     return blitter;
     95 }
     96 
     97