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