michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkDrawShader.h" michael@0: #include "SkDrawBitmap.h" michael@0: #include "SkDrawMatrix.h" michael@0: #include "SkDrawPaint.h" michael@0: #include "SkTemplates.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkDrawShader::fInfo[] = { michael@0: SK_MEMBER(matrix, Matrix), michael@0: SK_MEMBER(tileMode, TileMode) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkDrawShader); michael@0: michael@0: SkDrawShader::SkDrawShader() : matrix(NULL), michael@0: tileMode(SkShader::kClamp_TileMode) { michael@0: } michael@0: michael@0: bool SkDrawShader::add() { michael@0: if (fPaint->shader != (SkDrawShader*) -1) michael@0: return true; michael@0: fPaint->shader = this; michael@0: fPaint->fOwnsShader = true; michael@0: return false; michael@0: } michael@0: michael@0: void SkDrawShader::addPostlude(SkShader* shader) { michael@0: if (matrix) michael@0: shader->setLocalMatrix(matrix->getMatrix()); michael@0: } michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkDrawBitmapShader::fInfo[] = { michael@0: SK_MEMBER_INHERITED, michael@0: SK_MEMBER(filterBitmap, Boolean), michael@0: SK_MEMBER(image, BaseBitmap) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkDrawBitmapShader); michael@0: michael@0: SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {} michael@0: michael@0: bool SkDrawBitmapShader::add() { michael@0: if (fPaint->shader != (SkDrawShader*) -1) michael@0: return true; michael@0: fPaint->shader = this; michael@0: fPaint->fOwnsShader = true; michael@0: return false; michael@0: } michael@0: michael@0: SkShader* SkDrawBitmapShader::getShader() { michael@0: if (image == NULL) michael@0: return NULL; michael@0: michael@0: // note: bitmap shader now supports independent tile modes for X and Y michael@0: // we pass the same to both, but later we should extend this flexibility michael@0: // to the xml (e.g. tileModeX="repeat" tileModeY="clmap") michael@0: // michael@0: // oops, bitmapshader no longer takes filterBitmap, but deduces it at michael@0: // draw-time from the paint michael@0: SkShader* shader = SkShader::CreateBitmapShader(image->fBitmap, michael@0: (SkShader::TileMode) tileMode, michael@0: (SkShader::TileMode) tileMode); michael@0: SkAutoTDelete autoDel(shader); michael@0: addPostlude(shader); michael@0: (void)autoDel.detach(); michael@0: return shader; michael@0: }