| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  * Copyright 2013 Google Inc. |     2  * Copyright 2013 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 "SkBitmap.h" |     8 #include "SkBitmap.h" | 
|     9 #include "SkBitmapDevice.h" |     9 #include "SkBitmapDevice.h" | 
|    10 #include "SkBitmapSource.h" |    10 #include "SkBitmapSource.h" | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|    23 #include "SkMorphologyImageFilter.h" |    23 #include "SkMorphologyImageFilter.h" | 
|    24 #include "SkOffsetImageFilter.h" |    24 #include "SkOffsetImageFilter.h" | 
|    25 #include "SkPerlinNoiseShader.h" |    25 #include "SkPerlinNoiseShader.h" | 
|    26 #include "SkPicture.h" |    26 #include "SkPicture.h" | 
|    27 #include "SkPictureImageFilter.h" |    27 #include "SkPictureImageFilter.h" | 
|    28 #include "SkPictureRecorder.h" |    28 #include "SkPictureRecorder.h" | 
|    29 #include "SkPoint3.h" |    29 #include "SkPoint3.h" | 
|    30 #include "SkReadBuffer.h" |    30 #include "SkReadBuffer.h" | 
|    31 #include "SkRect.h" |    31 #include "SkRect.h" | 
|    32 #include "SkRectShaderImageFilter.h" |    32 #include "SkRectShaderImageFilter.h" | 
 |    33 #include "SkTableColorFilter.h" | 
|    33 #include "SkTileImageFilter.h" |    34 #include "SkTileImageFilter.h" | 
|    34 #include "SkXfermodeImageFilter.h" |    35 #include "SkXfermodeImageFilter.h" | 
|    35 #include "Test.h" |    36 #include "Test.h" | 
|    36  |    37  | 
|    37 #if SK_SUPPORT_GPU |    38 #if SK_SUPPORT_GPU | 
|    38 #include "GrContextFactory.h" |    39 #include "GrContextFactory.h" | 
|    39 #include "SkGpuDevice.h" |    40 #include "SkGpuDevice.h" | 
|    40 #endif |    41 #endif | 
|    41  |    42  | 
|    42 static const int kBitmapSize = 4; |    43 static const int kBitmapSize = 4; | 
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1152     SkBitmap result; |  1153     SkBitmap result; | 
|  1153     SkIPoint offset; |  1154     SkIPoint offset; | 
|  1154     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); |  1155     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); | 
|  1155     REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, 
      &offset)); |  1156     REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result, 
      &offset)); | 
|  1156     REPORTER_ASSERT(reporter, offset.fX == 0); |  1157     REPORTER_ASSERT(reporter, offset.fX == 0); | 
|  1157     REPORTER_ASSERT(reporter, offset.fY == 0); |  1158     REPORTER_ASSERT(reporter, offset.fY == 0); | 
|  1158     REPORTER_ASSERT(reporter, result.width() == 20); |  1159     REPORTER_ASSERT(reporter, result.width() == 20); | 
|  1159     REPORTER_ASSERT(reporter, result.height() == 30); |  1160     REPORTER_ASSERT(reporter, result.height() == 30); | 
|  1160 } |  1161 } | 
|  1161  |  1162  | 
 |  1163 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 
 |  1164  | 
 |  1165     SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 
 |  1166     SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDi
      ffuse( | 
 |  1167           location, SK_ColorGREEN, 0, 0)); | 
 |  1168     REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); | 
 |  1169  | 
 |  1170     SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); | 
 |  1171     REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); | 
 |  1172     { | 
 |  1173         SkColorFilter* grayCF; | 
 |  1174         REPORTER_ASSERT(reporter, gray->asAColorFilter(&grayCF)); | 
 |  1175         REPORTER_ASSERT(reporter, !grayCF->affectsTransparentBlack()); | 
 |  1176         grayCF->unref(); | 
 |  1177     } | 
 |  1178     REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); | 
 |  1179  | 
 |  1180     SkAutoTUnref<SkImageFilter> grayBlur(SkBlurImageFilter::Create(SK_Scalar1, S
      K_Scalar1, gray.get())); | 
 |  1181     REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds()); | 
 |  1182  | 
 |  1183     SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0, | 
 |  1184                                  0, 0, 0, 0, 1, | 
 |  1185                                  0, 0, 0, 0, 0, | 
 |  1186                                  0, 0, 0, 0, 1 }; | 
 |  1187     SkAutoTUnref<SkColorFilter> greenCF(SkColorMatrixFilter::Create(greenMatrix)
      ); | 
 |  1188     SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF))
      ; | 
 |  1189  | 
 |  1190     REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack()); | 
 |  1191     REPORTER_ASSERT(reporter, !green->canComputeFastBounds()); | 
 |  1192  | 
 |  1193     SkAutoTUnref<SkImageFilter> greenBlur(SkBlurImageFilter::Create(SK_Scalar1, 
      SK_Scalar1, green.get())); | 
 |  1194     REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds()); | 
 |  1195  | 
 |  1196     uint8_t allOne[256], identity[256]; | 
 |  1197     for (int i = 0; i < 256; ++i) { | 
 |  1198         identity[i] = i; | 
 |  1199         allOne[i] = 255; | 
 |  1200     } | 
 |  1201  | 
 |  1202     SkAutoTUnref<SkColorFilter> identityCF( | 
 |  1203         SkTableColorFilter::CreateARGB(identity, identity, identity, allOne)); | 
 |  1204     SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(
      identityCF.get())); | 
 |  1205     REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack()); | 
 |  1206     REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds()); | 
 |  1207  | 
 |  1208     SkAutoTUnref<SkColorFilter> forceOpaqueCF( | 
 |  1209         SkTableColorFilter::CreateARGB(allOne, identity, identity, identity)); | 
 |  1210     SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for
      ceOpaqueCF.get())); | 
 |  1211     REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); | 
 |  1212     REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); | 
 |  1213 } | 
 |  1214  | 
|  1162 #if SK_SUPPORT_GPU |  1215 #if SK_SUPPORT_GPU | 
|  1163  |  1216  | 
|  1164 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |  1217 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 
|  1165     GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
      e>(0)); |  1218     GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
      e>(0)); | 
|  1166     if (NULL == context) { |  1219     if (NULL == context) { | 
|  1167         return; |  1220         return; | 
|  1168     } |  1221     } | 
|  1169     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |  1222     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 
|  1170  |  1223  | 
|  1171     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |  1224     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1226                                                          SkSurface::kNo_Budgeted
      , |  1279                                                          SkSurface::kNo_Budgeted
      , | 
|  1227                                                          SkImageInfo::MakeN32Pre
      mul(1, 1), |  1280                                                          SkImageInfo::MakeN32Pre
      mul(1, 1), | 
|  1228                                                          0, |  1281                                                          0, | 
|  1229                                                          &props, |  1282                                                          &props, | 
|  1230                                                          SkGpuDevice::kUninit_In
      itContents)); |  1283                                                          SkGpuDevice::kUninit_In
      itContents)); | 
|  1231     SkImageFilter::Proxy proxy(device); |  1284     SkImageFilter::Proxy proxy(device); | 
|  1232  |  1285  | 
|  1233     test_negative_blur_sigma(&proxy, reporter); |  1286     test_negative_blur_sigma(&proxy, reporter); | 
|  1234 } |  1287 } | 
|  1235 #endif |  1288 #endif | 
| OLD | NEW |