OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 do { \ | 61 do { \ |
62 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 62 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
63 this->prepareDraw(draw); \ | 63 this->prepareDraw(draw); \ |
64 } while (0) | 64 } while (0) |
65 #else | 65 #else |
66 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) | 66 #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw) |
67 #endif | 67 #endif |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
71 /** Checks that the alpha type is legal and gets constructor flags. Returns fals
e if device creation | 71 /** Checks that the alpha type, color space, etc... is legal and gets constructo
r flags. |
72 should fail. */ | 72 Returns false if device creation should fail. */ |
73 bool SkGpuDevice::CheckAlphaTypeAndGetFlags( | 73 bool SkGpuDevice::CheckInfoAndGetFlags( |
74 const SkImageInfo* info, SkGpuDevice::InitContents init,
unsigned* flags) { | 74 const SkImageInfo* info, SkGpuDevice::InitContents init,
unsigned* flags) { |
| 75 if (info) { |
| 76 switch (info->colorType()) { |
| 77 case kRGBA_F16_SkColorType: |
| 78 if (!info->colorSpace() || |
| 79 SkColorSpace::kLinear_GammaNamed != info->colorSpace()->gamm
aNamed()) { |
| 80 return false; |
| 81 } |
| 82 break; |
| 83 case kRGBA_8888_SkColorType: |
| 84 case kBGRA_8888_SkColorType: |
| 85 if (info->colorSpace() && !info->colorSpace()->gammaCloseToSRGB(
)) { |
| 86 return false; |
| 87 } |
| 88 break; |
| 89 default: |
| 90 if (info->colorSpace()) { |
| 91 return false; |
| 92 } |
| 93 } |
| 94 } |
| 95 |
75 *flags = 0; | 96 *flags = 0; |
76 if (info) { | 97 if (info) { |
77 switch (info->alphaType()) { | 98 switch (info->alphaType()) { |
78 case kPremul_SkAlphaType: | 99 case kPremul_SkAlphaType: |
79 break; | 100 break; |
80 case kOpaque_SkAlphaType: | 101 case kOpaque_SkAlphaType: |
81 *flags |= SkGpuDevice::kIsOpaque_Flag; | 102 *flags |= SkGpuDevice::kIsOpaque_Flag; |
82 break; | 103 break; |
83 default: // If it is unpremul or unknown don't try to render | 104 default: // If it is unpremul or unknown don't try to render |
84 return false; | 105 return false; |
85 } | 106 } |
86 } | 107 } |
87 if (kClear_InitContents == init) { | 108 if (kClear_InitContents == init) { |
88 *flags |= kNeedClear_Flag; | 109 *flags |= kNeedClear_Flag; |
89 } | 110 } |
90 return true; | 111 return true; |
91 } | 112 } |
92 | 113 |
93 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, | 114 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, |
94 int width, int height, | 115 int width, int height, |
95 InitContents init) { | 116 InitContents init) { |
96 if (!drawContext || drawContext->wasAbandoned()) { | 117 if (!drawContext || drawContext->wasAbandoned()) { |
97 return nullptr; | 118 return nullptr; |
98 } | 119 } |
99 unsigned flags; | 120 unsigned flags; |
100 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 121 if (!CheckInfoAndGetFlags(nullptr, init, &flags)) { |
101 return nullptr; | 122 return nullptr; |
102 } | 123 } |
103 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei
ght, flags)); | 124 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei
ght, flags)); |
104 } | 125 } |
105 | 126 |
106 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, | 127 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
107 const SkImageInfo& info, int sampleCount, | 128 const SkImageInfo& info, int sampleCount, |
108 GrSurfaceOrigin origin, | 129 GrSurfaceOrigin origin, |
109 const SkSurfaceProps* props, InitContents i
nit) { | 130 const SkSurfaceProps* props, InitContents i
nit) { |
110 unsigned flags; | 131 unsigned flags; |
111 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 132 if (!CheckInfoAndGetFlags(&info, init, &flags)) { |
112 return nullptr; | 133 return nullptr; |
113 } | 134 } |
114 | 135 |
115 sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info, | 136 sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info, |
116 sampleCount, origin, props)
); | 137 sampleCount, origin, props)
); |
117 if (!drawContext) { | 138 if (!drawContext) { |
118 return nullptr; | 139 return nullptr; |
119 } | 140 } |
120 | 141 |
121 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), | 142 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), |
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 } | 1828 } |
1808 | 1829 |
1809 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1830 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1810 ASSERT_SINGLE_OWNER | 1831 ASSERT_SINGLE_OWNER |
1811 // We always return a transient cache, so it is freed after each | 1832 // We always return a transient cache, so it is freed after each |
1812 // filter traversal. | 1833 // filter traversal. |
1813 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1834 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1814 } | 1835 } |
1815 | 1836 |
1816 #endif | 1837 #endif |
OLD | NEW |