OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 int left, int top, const SkPaint& paint) { | 1135 int left, int top, const SkPaint& paint) { |
1136 ASSERT_SINGLE_OWNER | 1136 ASSERT_SINGLE_OWNER |
1137 // drawSprite is defined to be in device coords. | 1137 // drawSprite is defined to be in device coords. |
1138 CHECK_SHOULD_DRAW(draw); | 1138 CHECK_SHOULD_DRAW(draw); |
1139 | 1139 |
1140 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); | 1140 SkAutoLockPixels alp(bitmap, !bitmap.getTexture()); |
1141 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { | 1141 if (!bitmap.getTexture() && !bitmap.readyToDraw()) { |
1142 return; | 1142 return; |
1143 } | 1143 } |
1144 | 1144 |
| 1145 int offX = bitmap.pixelRefOrigin().fX; |
| 1146 int offY = bitmap.pixelRefOrigin().fY; |
1145 int w = bitmap.width(); | 1147 int w = bitmap.width(); |
1146 int h = bitmap.height(); | 1148 int h = bitmap.height(); |
1147 | 1149 |
1148 GrTexture* texture; | 1150 GrTexture* texture; |
1149 // draw sprite neither filters nor tiles. | 1151 // draw sprite neither filters nor tiles. |
1150 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t
exture); | 1152 AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &t
exture); |
1151 if (!texture) { | 1153 if (!texture) { |
1152 return; | 1154 return; |
1153 } | 1155 } |
1154 | 1156 |
1155 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); | 1157 bool alphaOnly = kAlpha_8_SkColorType == bitmap.colorType(); |
1156 | 1158 |
1157 SkImageFilter* filter = paint.getImageFilter(); | 1159 SkImageFilter* filter = paint.getImageFilter(); |
1158 // This bitmap will own the filtered result as a texture. | 1160 // This bitmap will own the filtered result as a texture. |
1159 SkBitmap filteredBitmap; | 1161 SkBitmap filteredBitmap; |
1160 | 1162 |
1161 if (filter) { | 1163 if (filter) { |
1162 SkIPoint offset = SkIPoint::Make(0, 0); | 1164 SkIPoint offset = SkIPoint::Make(0, 0); |
1163 SkMatrix matrix(*draw.fMatrix); | 1165 SkMatrix matrix(*draw.fMatrix); |
1164 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); | 1166 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); |
1165 SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-left, -top); | 1167 SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-left, -top); |
1166 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); | 1168 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); |
1167 // This cache is transient, and is freed (along with all its contained | 1169 // This cache is transient, and is freed (along with all its contained |
1168 // textures) when it goes out of scope. | 1170 // textures) when it goes out of scope. |
1169 SkImageFilter::Context ctx(matrix, clipBounds, cache); | 1171 SkImageFilter::Context ctx(matrix, clipBounds, cache); |
1170 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB
itmap, | 1172 if (this->filterTexture(fContext, texture, w, h, filter, ctx, &filteredB
itmap, |
1171 &offset)) { | 1173 &offset)) { |
1172 texture = (GrTexture*) filteredBitmap.getTexture(); | 1174 texture = (GrTexture*) filteredBitmap.getTexture(); |
| 1175 offX = filteredBitmap.pixelRefOrigin().fX; |
| 1176 offY = filteredBitmap.pixelRefOrigin().fY; |
1173 w = filteredBitmap.width(); | 1177 w = filteredBitmap.width(); |
1174 h = filteredBitmap.height(); | 1178 h = filteredBitmap.height(); |
1175 left += offset.x(); | 1179 left += offset.x(); |
1176 top += offset.y(); | 1180 top += offset.y(); |
1177 } else { | 1181 } else { |
1178 return; | 1182 return; |
1179 } | 1183 } |
1180 SkASSERT(!GrPixelConfigIsAlphaOnly(texture->config())); | 1184 SkASSERT(!GrPixelConfigIsAlphaOnly(texture->config())); |
1181 alphaOnly = false; | 1185 alphaOnly = false; |
1182 } | 1186 } |
(...skipping 10 matching lines...) Expand all Loading... |
1193 return; | 1197 return; |
1194 } | 1198 } |
1195 | 1199 |
1196 fDrawContext->fillRectToRect(fClip, | 1200 fDrawContext->fillRectToRect(fClip, |
1197 grPaint, | 1201 grPaint, |
1198 SkMatrix::I(), | 1202 SkMatrix::I(), |
1199 SkRect::MakeXYWH(SkIntToScalar(left), | 1203 SkRect::MakeXYWH(SkIntToScalar(left), |
1200 SkIntToScalar(top), | 1204 SkIntToScalar(top), |
1201 SkIntToScalar(w), | 1205 SkIntToScalar(w), |
1202 SkIntToScalar(h)), | 1206 SkIntToScalar(h)), |
1203 SkRect::MakeXYWH(0, | 1207 SkRect::MakeXYWH(SkIntToScalar(offX) / texture-
>width(), |
1204 0, | 1208 SkIntToScalar(offY) / texture-
>height(), |
1205 SK_Scalar1 * w / texture->widt
h(), | 1209 SkIntToScalar(w) / texture->wi
dth(), |
1206 SK_Scalar1 * h / texture->heig
ht())); | 1210 SkIntToScalar(h) / texture->he
ight())); |
1207 } | 1211 } |
1208 | 1212 |
1209 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 1213 void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
1210 const SkRect* src, const SkRect& origDst, | 1214 const SkRect* src, const SkRect& origDst, |
1211 const SkPaint& paint, SkCanvas::SrcRectConstrai
nt constraint) { | 1215 const SkPaint& paint, SkCanvas::SrcRectConstrai
nt constraint) { |
1212 ASSERT_SINGLE_OWNER | 1216 ASSERT_SINGLE_OWNER |
1213 CHECK_SHOULD_DRAW(draw); | 1217 CHECK_SHOULD_DRAW(draw); |
1214 if (bitmap.getTexture()) { | 1218 if (bitmap.getTexture()) { |
1215 GrBitmapTextureAdjuster adjuster(&bitmap); | 1219 GrBitmapTextureAdjuster adjuster(&bitmap); |
1216 this->drawTextureProducer(&adjuster, src, &origDst, constraint, *draw.fM
atrix, fClip, | 1220 this->drawTextureProducer(&adjuster, src, &origDst, constraint, *draw.fM
atrix, fClip, |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 } | 1882 } |
1879 | 1883 |
1880 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1884 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1881 ASSERT_SINGLE_OWNER | 1885 ASSERT_SINGLE_OWNER |
1882 // We always return a transient cache, so it is freed after each | 1886 // We always return a transient cache, so it is freed after each |
1883 // filter traversal. | 1887 // filter traversal. |
1884 return SkGpuDevice::NewImageFilterCache(); | 1888 return SkGpuDevice::NewImageFilterCache(); |
1885 } | 1889 } |
1886 | 1890 |
1887 #endif | 1891 #endif |
OLD | NEW |