| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 origInfo.width() < 0 || origInfo.height() < 0) { | 186 origInfo.width() < 0 || origInfo.height() < 0) { |
| 187 return nullptr; | 187 return nullptr; |
| 188 } | 188 } |
| 189 | 189 |
| 190 if (!context) { | 190 if (!context) { |
| 191 return nullptr; | 191 return nullptr; |
| 192 } | 192 } |
| 193 | 193 |
| 194 SkColorType ct = origInfo.colorType(); | 194 SkColorType ct = origInfo.colorType(); |
| 195 SkAlphaType at = origInfo.alphaType(); | 195 SkAlphaType at = origInfo.alphaType(); |
| 196 SkColorProfileType pt = origInfo.profileType(); |
| 196 if (kRGB_565_SkColorType == ct) { | 197 if (kRGB_565_SkColorType == ct) { |
| 197 at = kOpaque_SkAlphaType; // force this setting | 198 at = kOpaque_SkAlphaType; // force this setting |
| 198 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { | 199 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
| 199 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 200 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
| 200 ct = kN32_SkColorType; | 201 ct = kN32_SkColorType; |
| 201 } | 202 } |
| 202 if (kOpaque_SkAlphaType != at) { | 203 if (kOpaque_SkAlphaType != at) { |
| 203 at = kPremul_SkAlphaType; // force this setting | 204 at = kPremul_SkAlphaType; // force this setting |
| 204 } | 205 } |
| 205 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 206 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at, pt); |
| 206 | 207 |
| 207 GrSurfaceDesc desc; | 208 GrSurfaceDesc desc; |
| 208 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 209 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 209 desc.fWidth = info.width(); | 210 desc.fWidth = info.width(); |
| 210 desc.fHeight = info.height(); | 211 desc.fHeight = info.height(); |
| 211 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 212 desc.fConfig = SkImageInfo2GrPixelConfig(info, *context->caps()); |
| 212 desc.fSampleCnt = sampleCount; | 213 desc.fSampleCnt = sampleCount; |
| 213 desc.fTextureStorageAllocator = textureStorageAllocator; | 214 desc.fTextureStorageAllocator = textureStorageAllocator; |
| 214 desc.fIsMipMapped = false; | 215 desc.fIsMipMapped = false; |
| 215 GrTexture* texture = context->textureProvider()->createTexture(desc, budgete
d, nullptr, 0); | 216 GrTexture* texture = context->textureProvider()->createTexture(desc, budgete
d, nullptr, 0); |
| 216 if (nullptr == texture) { | 217 if (nullptr == texture) { |
| 217 return nullptr; | 218 return nullptr; |
| 218 } | 219 } |
| 219 SkASSERT(nullptr != texture->asRenderTarget()); | 220 SkASSERT(nullptr != texture->asRenderTarget()); |
| 220 return texture->asRenderTarget(); | 221 return texture->asRenderTarget(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 /////////////////////////////////////////////////////////////////////////////// | 224 /////////////////////////////////////////////////////////////////////////////// |
| 224 | 225 |
| 225 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, | 226 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, |
| 226 int x, int y) { | 227 int x, int y) { |
| 227 ASSERT_SINGLE_OWNER | 228 ASSERT_SINGLE_OWNER |
| 228 | 229 |
| 229 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 230 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 230 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); | 231 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps())
; |
| 231 if (kUnknown_GrPixelConfig == config) { | 232 if (kUnknown_GrPixelConfig == config) { |
| 232 return false; | 233 return false; |
| 233 } | 234 } |
| 234 | 235 |
| 235 uint32_t flags = 0; | 236 uint32_t flags = 0; |
| 236 if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { | 237 if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { |
| 237 flags = GrContext::kUnpremul_PixelOpsFlag; | 238 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 238 } | 239 } |
| 239 return fRenderTarget->readPixels(x, y, dstInfo.width(), dstInfo.height(), co
nfig, dstPixels, | 240 return fRenderTarget->readPixels(x, y, dstInfo.width(), dstInfo.height(), co
nfig, dstPixels, |
| 240 dstRowBytes, flags); | 241 dstRowBytes, flags); |
| 241 } | 242 } |
| 242 | 243 |
| 243 bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, | 244 bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, |
| 244 int x, int y) { | 245 int x, int y) { |
| 245 ASSERT_SINGLE_OWNER | 246 ASSERT_SINGLE_OWNER |
| 246 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 247 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 247 GrPixelConfig config = SkImageInfo2GrPixelConfig(info); | 248 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); |
| 248 if (kUnknown_GrPixelConfig == config) { | 249 if (kUnknown_GrPixelConfig == config) { |
| 249 return false; | 250 return false; |
| 250 } | 251 } |
| 251 uint32_t flags = 0; | 252 uint32_t flags = 0; |
| 252 if (kUnpremul_SkAlphaType == info.alphaType()) { | 253 if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 253 flags = GrContext::kUnpremul_PixelOpsFlag; | 254 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 254 } | 255 } |
| 255 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); | 256 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); |
| 256 | 257 |
| 257 // need to bump our genID for compatibility with clients that "know" we have
a bitmap | 258 // need to bump our genID for compatibility with clients that "know" we have
a bitmap |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 } | 1883 } |
| 1883 | 1884 |
| 1884 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1885 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1885 ASSERT_SINGLE_OWNER | 1886 ASSERT_SINGLE_OWNER |
| 1886 // We always return a transient cache, so it is freed after each | 1887 // We always return a transient cache, so it is freed after each |
| 1887 // filter traversal. | 1888 // filter traversal. |
| 1888 return SkGpuDevice::NewImageFilterCache(); | 1889 return SkGpuDevice::NewImageFilterCache(); |
| 1889 } | 1890 } |
| 1890 | 1891 |
| 1891 #endif | 1892 #endif |
| OLD | NEW |