| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
| 11 #include "SkRRect.h" | 11 #include "SkRRect.h" |
| 12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
| 13 #include "SkUtils.h" | 13 #include "SkUtils.h" |
| 14 #include "RefCntIs.h" | |
| 15 #include "Test.h" | 14 #include "Test.h" |
| 16 | 15 |
| 17 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 18 #include "GrContextFactory.h" | 17 #include "GrContextFactory.h" |
| 19 #else | 18 #else |
| 20 class GrContextFactory; | 19 class GrContextFactory; |
| 21 class GrContext; | 20 class GrContext; |
| 22 #endif | 21 #endif |
| 23 | 22 |
| 24 enum SurfaceType { | 23 enum SurfaceType { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 kCodec_ImageType, | 70 kCodec_ImageType, |
| 72 }; | 71 }; |
| 73 | 72 |
| 74 static void test_image(skiatest::Reporter* reporter) { | 73 static void test_image(skiatest::Reporter* reporter) { |
| 75 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); | 74 SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 76 size_t rowBytes = info.minRowBytes(); | 75 size_t rowBytes = info.minRowBytes(); |
| 77 size_t size = info.getSafeSize(rowBytes); | 76 size_t size = info.getSafeSize(rowBytes); |
| 78 void* addr = sk_malloc_throw(size); | 77 void* addr = sk_malloc_throw(size); |
| 79 SkData* data = SkData::NewFromMalloc(addr, size); | 78 SkData* data = SkData::NewFromMalloc(addr, size); |
| 80 | 79 |
| 81 REPORTER_ASSERT(reporter, RefCntIs(*data, 1)); | 80 REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); |
| 82 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); | 81 SkImage* image = SkImage::NewRasterData(info, data, rowBytes); |
| 83 REPORTER_ASSERT(reporter, RefCntIs(*data, 2)); | 82 REPORTER_ASSERT(reporter, 2 == data->getRefCnt()); |
| 84 image->unref(); | 83 image->unref(); |
| 85 REPORTER_ASSERT(reporter, RefCntIs(*data, 1)); | 84 REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); |
| 86 data->unref(); | 85 data->unref(); |
| 87 } | 86 } |
| 88 | 87 |
| 89 static SkImage* createImage(ImageType imageType, GrContext* context, | 88 static SkImage* createImage(ImageType imageType, GrContext* context, |
| 90 SkColor color) { | 89 SkColor color) { |
| 91 const SkPMColor pmcolor = SkPreMultiplyColor(color); | 90 const SkPMColor pmcolor = SkPreMultiplyColor(color); |
| 92 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); | 91 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| 93 const size_t rowBytes = info.minRowBytes(); | 92 const size_t rowBytes = info.minRowBytes(); |
| 94 const size_t size = rowBytes * info.fHeight; | 93 const size_t size = rowBytes * info.fHeight; |
| 95 | 94 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kDiscard_ContentChangeMode); | 442 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kDiscard_ContentChangeMode); |
| 444 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kDiscard_ContentChangeMode); | 443 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kDiscard_ContentChangeMode); |
| 445 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kRetain_ContentChangeMode); | 444 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::
kRetain_ContentChangeMode); |
| 446 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kRetain_ContentChangeMode); | 445 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSu
rface::kRetain_ContentChangeMode); |
| 447 TestGetTexture(reporter, kGpu_SurfaceType, context); | 446 TestGetTexture(reporter, kGpu_SurfaceType, context); |
| 448 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 447 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
| 449 } | 448 } |
| 450 } | 449 } |
| 451 #endif | 450 #endif |
| 452 } | 451 } |
| OLD | NEW |