| OLD | NEW | 
|---|
| 1 | 1 | 
| 2 /* | 2 /* | 
| 3  * Copyright 2014 Google Inc. | 3  * Copyright 2014 Google Inc. | 
| 4  * | 4  * | 
| 5  * Use of this source code is governed by a BSD-style license that can be | 5  * Use of this source code is governed by a BSD-style license that can be | 
| 6  * found in the LICENSE file. | 6  * found in the LICENSE file. | 
| 7  */ | 7  */ | 
| 8 | 8 | 
| 9 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. | 
| 10 | 10 | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 28     TextureDomainEffect() { | 28     TextureDomainEffect() { | 
| 29         this->setBGColor(0xFFFFFFFF); | 29         this->setBGColor(0xFFFFFFFF); | 
| 30     } | 30     } | 
| 31 | 31 | 
| 32 protected: | 32 protected: | 
| 33     virtual SkString onShortName() SK_OVERRIDE { | 33     virtual SkString onShortName() SK_OVERRIDE { | 
| 34         return SkString("texture_domain_effect"); | 34         return SkString("texture_domain_effect"); | 
| 35     } | 35     } | 
| 36 | 36 | 
| 37     virtual SkISize onISize() SK_OVERRIDE { | 37     virtual SkISize onISize() SK_OVERRIDE { | 
| 38         return SkISize::Make(400, 800); | 38         const SkScalar canvasWidth = kDrawPad + | 
|  | 39                 (kTargetWidth + 2 * kDrawPad) * GrTextureDomain::kModeCount + | 
|  | 40                 kTestPad * GrTextureDomain::kModeCount; | 
|  | 41         return SkISize::Make(SkScalarCeilToInt(canvasWidth), 800); | 
| 39     } | 42     } | 
| 40 | 43 | 
| 41     virtual uint32_t onGetFlags() const SK_OVERRIDE { | 44     virtual uint32_t onGetFlags() const SK_OVERRIDE { | 
| 42         // This is a GPU-specific GM. | 45         // This is a GPU-specific GM. | 
| 43         return kGPUOnly_Flag; | 46         return kGPUOnly_Flag; | 
| 44     } | 47     } | 
| 45 | 48 | 
| 46     virtual void onOnceBeforeDraw() SK_OVERRIDE { | 49     virtual void onOnceBeforeDraw() SK_OVERRIDE { | 
| 47         fBmp.allocN32Pixels(100, 100); | 50         fBmp.allocN32Pixels(kTargetWidth, kTargetHeight); | 
| 48         SkCanvas canvas(fBmp); | 51         SkCanvas canvas(fBmp); | 
| 49         canvas.clear(0x00000000); | 52         canvas.clear(0x00000000); | 
| 50         SkPaint paint; | 53         SkPaint paint; | 
| 51 | 54 | 
| 52         SkColor colors1[] = { SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGRAY }; | 55         SkColor colors1[] = { SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGRAY }; | 
| 53         paint.setShader(SkGradientShader::CreateSweep(65.f, 75.f, colors1, | 56         paint.setShader(SkGradientShader::CreateSweep(65.f, 75.f, colors1, | 
| 54                                                       NULL, SK_ARRAY_COUNT(color
     s1)))->unref(); | 57                                                       NULL, SK_ARRAY_COUNT(color
     s1)))->unref(); | 
| 55         canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, | 58         canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, | 
| 56                                          fBmp.width() + 10.f, fBmp.height() + 10
     .f), paint); | 59                                          fBmp.width() + 10.f, fBmp.height() + 10
     .f), paint); | 
| 57 | 60 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 87             return; | 90             return; | 
| 88         } | 91         } | 
| 89 | 92 | 
| 90         GrDrawState* drawState = tt.target()->drawState(); | 93         GrDrawState* drawState = tt.target()->drawState(); | 
| 91 | 94 | 
| 92         GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fBmp, NULL
     ); | 95         GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fBmp, NULL
     ); | 
| 93         if (NULL == texture) { | 96         if (NULL == texture) { | 
| 94             return; | 97             return; | 
| 95         } | 98         } | 
| 96 | 99 | 
| 97         static const SkScalar kDrawPad = 10.f; |  | 
| 98         static const SkScalar kTestPad = 10.f; |  | 
| 99 |  | 
| 100         SkTArray<SkMatrix> textureMatrices; | 100         SkTArray<SkMatrix> textureMatrices; | 
| 101         textureMatrices.push_back().setIDiv(texture->width(), texture->height())
     ; | 101         textureMatrices.push_back().setIDiv(texture->width(), texture->height())
     ; | 
| 102         textureMatrices.push_back() = textureMatrices[0]; | 102         textureMatrices.push_back() = textureMatrices[0]; | 
| 103         textureMatrices.back().postScale(1.5f, 0.85f); | 103         textureMatrices.back().postScale(1.5f, 0.85f); | 
| 104         textureMatrices.push_back() = textureMatrices[0]; | 104         textureMatrices.push_back() = textureMatrices[0]; | 
| 105         textureMatrices.back().preRotate(45.f, texture->width() / 2.f, texture->
     height() / 2.f); | 105         textureMatrices.back().preRotate(45.f, texture->width() / 2.f, texture->
     height() / 2.f); | 
| 106 | 106 | 
| 107         const SkIRect texelDomains[] = { | 107         const SkIRect texelDomains[] = { | 
| 108             SkIRect::MakeWH(fBmp.width(), fBmp.height()), | 108             SkIRect::MakeWH(fBmp.width(), fBmp.height()), | 
| 109             SkIRect::MakeXYWH(fBmp.width() / 4, | 109             SkIRect::MakeXYWH(fBmp.width() / 4, | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 141                     tt.target()->drawSimpleRect(renderRect); | 141                     tt.target()->drawSimpleRect(renderRect); | 
| 142                     x += renderRect.width() + kTestPad; | 142                     x += renderRect.width() + kTestPad; | 
| 143                 } | 143                 } | 
| 144                 y += renderRect.height() + kTestPad; | 144                 y += renderRect.height() + kTestPad; | 
| 145             } | 145             } | 
| 146         } | 146         } | 
| 147         GrUnlockAndUnrefCachedBitmapTexture(texture); | 147         GrUnlockAndUnrefCachedBitmapTexture(texture); | 
| 148     } | 148     } | 
| 149 | 149 | 
| 150 private: | 150 private: | 
|  | 151     static const SkScalar kDrawPad; | 
|  | 152     static const SkScalar kTestPad; | 
|  | 153     static const int      kTargetWidth = 100; | 
|  | 154     static const int      kTargetHeight = 100; | 
| 151     SkBitmap fBmp; | 155     SkBitmap fBmp; | 
| 152 | 156 | 
| 153     typedef GM INHERITED; | 157     typedef GM INHERITED; | 
| 154 }; | 158 }; | 
| 155 | 159 | 
|  | 160 // Windows builds did not like SkScalar initialization in class :( | 
|  | 161 const SkScalar TextureDomainEffect::kDrawPad = 10.f; | 
|  | 162 const SkScalar TextureDomainEffect::kTestPad = 10.f; | 
|  | 163 | 
| 156 DEF_GM( return SkNEW(TextureDomainEffect); ) | 164 DEF_GM( return SkNEW(TextureDomainEffect); ) | 
| 157 } | 165 } | 
| 158 | 166 | 
| 159 #endif | 167 #endif | 
| OLD | NEW | 
|---|