1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #if SK_SUPPORT_GPU
10
11 #include "GrContext.h"
12 #include "GrContextFactory.h"
13 #include "SkBitmap.h"
14 #include "SkCanvas.h"
15 #include "SkColor.h"
16 #include "SkGpuDevice.h"
17 #include "SkPaint.h"
18 #include "SkRect.h"
19 #include "SkRRect.h"
20 #include "Test.h"
21
test_drawPathEmpty(skiatest::Reporter *,SkCanvas * canvas)22 static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas)
23 {
24 // Filling an empty path should not crash.
25 SkPaint paint;
26 canvas->drawRect(SkRect(), paint);
27 canvas->drawPath(SkPath(), paint);
28 canvas->drawOval(SkRect(), paint);
29 canvas->drawRect(SkRect(), paint);
30 canvas->drawRRect(SkRRect(), paint);
31
32 // Stroking an empty path should not crash.
33 paint.setAntiAlias(true);
34 paint.setStyle(SkPaint::kStroke_Style);
35 paint.setColor(SK_ColorGRAY);
36 paint.setStrokeWidth(SkIntToScalar(20));
37 paint.setStrokeJoin(SkPaint::kRound_Join);
38 canvas->drawRect(SkRect(), paint);
39 canvas->drawPath(SkPath(), paint);
40 canvas->drawOval(SkRect(), paint);
41 canvas->drawRect(SkRect(), paint);
42 canvas->drawRRect(SkRRect(), paint);
43 }
44
45
TestGpuDrawPath(skiatest::Reporter * reporter,GrContextFactory * factory)46 static void TestGpuDrawPath(skiatest::Reporter* reporter, GrContextFactory* factory) {
47 return;
48
49 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
50 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
51
52 GrContext* grContext = factory->get(glType);
53 if (NULL == grContext) {
54 continue;
55 }
56 static const int sampleCounts[] = { 0, 4, 16 };
57
58 for (size_t i = 0; i < SK_ARRAY_COUNT(sampleCounts); ++i) {
59 const int W = 255;
60 const int H = 255;
61
62 GrTextureDesc desc;
63 desc.fConfig = kSkia8888_GrPixelConfig;
64 desc.fFlags = kRenderTarget_GrTextureFlagBit;
65 desc.fWidth = W;
66 desc.fHeight = H;
67 desc.fSampleCnt = sampleCounts[i];
68 SkAutoTUnref<GrTexture> texture(grContext->createUncachedTexture(desc, NULL, 0));
69 SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice, (grContext, texture.get())));
70 SkCanvas drawingCanvas(device.get());
71
72 test_drawPathEmpty(reporter, &drawingCanvas);
73 }
74 }
75 }
76
77 #include "TestClassDef.h"
78 DEFINE_GPUTESTCLASS("GpuDrawPath", TestGpuDrawPathClass, TestGpuDrawPath)
79
80 #endif
81