OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkNormalSource_DEFINED |
| 9 #define SkNormalSource_DEFINED |
| 10 |
| 11 #include "SkFlattenable.h" |
| 12 |
| 13 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. Not to be |
| 14 used as part of the API yet. Used internally by SkLightingShader. |
| 15 */ |
| 16 class SK_API SkNormalSource : public SkFlattenable { |
| 17 public: |
| 18 virtual ~SkNormalSource(); |
| 19 |
| 20 #if SK_SUPPORT_GPU |
| 21 /** Returns a fragment processor that takes no input and outputs a normal (a
lready rotated) |
| 22 as its output color. To be used as a child fragment processor. |
| 23 */ |
| 24 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( |
| 25 GrContext* context, |
| 26 const SkMatrix& viewM, |
| 27 const SkMatrix* localMatrix, |
| 28 SkFilterQuality filterQuality, |
| 29 SkSourceGammaTreatment gammaTreatment) const = 0; |
| 30 #endif |
| 31 |
| 32 class Provider { |
| 33 public: |
| 34 virtual ~Provider() {}; |
| 35 |
| 36 /** Called for each span of the object being drawn on the CPU. Your subc
lass should set |
| 37 the appropriate normals that correspond to the specified device coor
dinates. |
| 38 */ |
| 39 virtual void fillScanLine(int x, int y, SkPoint3 output[], int count) co
nst = 0; |
| 40 }; |
| 41 |
| 42 /** Returns an instance of 'Provider' that provides normals for the CPU pipe
line. The |
| 43 necessary data will be initialized in place at 'storage'. |
| 44 */ |
| 45 virtual Provider* asProvider(const SkShader::ContextRec&, void* storage) con
st = 0; |
| 46 |
| 47 /** Amount of memory needed to store a provider object and its dependencies. |
| 48 */ |
| 49 virtual size_t providerSize(const SkShader::ContextRec&) const = 0; |
| 50 |
| 51 /** Returns a normal source that provides normals sourced from the the norma
l map argument. |
| 52 Not to be used as part of the API yet. Used internally by SkLightingSh
ader. |
| 53 |
| 54 @param normal the normal map |
| 55 @param invNormRotation rotation applied to the normal map's nor
mals |
| 56 @param normLocalM the local matrix for the normal map |
| 57 |
| 58 nullptr will be returned if |
| 59 'normal' is empty |
| 60 'normal' too big (> 65535 on either side) |
| 61 |
| 62 The normal map is currently assumed to be an 8888 image where the norm
al at a texel |
| 63 is retrieved by: |
| 64 N.x = R-127; |
| 65 N.y = G-127; |
| 66 N.z = B-127; |
| 67 N.normalize(); |
| 68 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is |
| 69 (127, 127, 0). |
| 70 */ |
| 71 static sk_sp<SkNormalSource> MakeMap(const SkBitmap& normal, const SkVector&
invNormRotation, |
| 72 const SkMatrix* normLocalM); |
| 73 |
| 74 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) |
| 75 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
| 76 }; |
| 77 |
| 78 #endif |
OLD | NEW |