| 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 "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 fRenderTarget->ref(); | 193 fRenderTarget->ref(); |
| 194 | 194 |
| 195 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 195 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
| 196 // on the RT but not vice-versa. | 196 // on the RT but not vice-versa. |
| 197 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 197 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
| 198 // busting chrome (for a currently unknown reason). | 198 // busting chrome (for a currently unknown reason). |
| 199 GrSurface* surface = fRenderTarget->asTexture(); | 199 GrSurface* surface = fRenderTarget->asTexture(); |
| 200 if (NULL == surface) { | 200 if (NULL == surface) { |
| 201 surface = fRenderTarget; | 201 surface = fRenderTarget; |
| 202 } | 202 } |
| 203 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); | 203 |
| 204 SkImageInfo info; |
| 205 surface->asImageInfo(&info); |
| 206 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, cached)); |
| 204 | 207 |
| 205 this->setPixelRef(pr, 0)->unref(); | 208 this->setPixelRef(pr, 0)->unref(); |
| 206 } | 209 } |
| 207 | 210 |
| 208 SkGpuDevice::SkGpuDevice(GrContext* context, | 211 SkGpuDevice::SkGpuDevice(GrContext* context, |
| 209 SkBitmap::Config config, | 212 SkBitmap::Config config, |
| 210 int width, | 213 int width, |
| 211 int height, | 214 int height, |
| 212 int sampleCount) | 215 int sampleCount) |
| 213 : SkBitmapDevice(config, width, height, false /*isOpaque*/) { | 216 : SkBitmapDevice(config, width, height, false /*isOpaque*/) |
| 214 | 217 { |
| 215 fDrawProcs = NULL; | 218 fDrawProcs = NULL; |
| 216 | 219 |
| 217 fContext = context; | 220 fContext = context; |
| 218 fContext->ref(); | 221 fContext->ref(); |
| 219 | 222 |
| 220 fRenderTarget = NULL; | 223 fRenderTarget = NULL; |
| 221 fNeedClear = false; | 224 fNeedClear = false; |
| 222 | 225 |
| 223 if (config != SkBitmap::kRGB_565_Config) { | 226 if (config != SkBitmap::kRGB_565_Config) { |
| 224 config = SkBitmap::kARGB_8888_Config; | 227 config = SkBitmap::kARGB_8888_Config; |
| 225 } | 228 } |
| 226 | 229 |
| 227 GrTextureDesc desc; | 230 GrTextureDesc desc; |
| 228 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 231 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 229 desc.fWidth = width; | 232 desc.fWidth = width; |
| 230 desc.fHeight = height; | 233 desc.fHeight = height; |
| 231 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 234 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); |
| 232 desc.fSampleCnt = sampleCount; | 235 desc.fSampleCnt = sampleCount; |
| 233 | 236 |
| 237 SkImageInfo info; |
| 238 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { |
| 239 sk_throw(); |
| 240 } |
| 241 info.fWidth = width; |
| 242 info.fHeight = height; |
| 243 info.fAlphaType = kPremul_SkAlphaType; |
| 244 |
| 234 SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL,
0)); | 245 SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL,
0)); |
| 235 | 246 |
| 236 if (NULL != texture) { | 247 if (NULL != texture) { |
| 237 fRenderTarget = texture->asRenderTarget(); | 248 fRenderTarget = texture->asRenderTarget(); |
| 238 fRenderTarget->ref(); | 249 fRenderTarget->ref(); |
| 239 | 250 |
| 240 SkASSERT(NULL != fRenderTarget); | 251 SkASSERT(NULL != fRenderTarget); |
| 241 | 252 |
| 242 // wrap the bitmap with a pixelref to expose our texture | 253 // wrap the bitmap with a pixelref to expose our texture |
| 243 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (texture)); | 254 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); |
| 244 this->setPixelRef(pr, 0)->unref(); | 255 this->setPixelRef(pr, 0)->unref(); |
| 245 } else { | 256 } else { |
| 246 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", | 257 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", |
| 247 width, height); | 258 width, height); |
| 248 SkASSERT(false); | 259 SkASSERT(false); |
| 249 } | 260 } |
| 250 } | 261 } |
| 251 | 262 |
| 252 SkGpuDevice::~SkGpuDevice() { | 263 SkGpuDevice::~SkGpuDevice() { |
| 253 if (fDrawProcs) { | 264 if (fDrawProcs) { |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 | 830 |
| 820 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. | 831 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. |
| 821 SkMatrix translate; | 832 SkMatrix translate; |
| 822 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); | 833 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
| 823 am.set(context, translate); | 834 am.set(context, translate); |
| 824 context->drawPath(tempPaint, devPath, stroke); | 835 context->drawPath(tempPaint, devPath, stroke); |
| 825 return true; | 836 return true; |
| 826 } | 837 } |
| 827 | 838 |
| 828 SkBitmap wrap_texture(GrTexture* texture) { | 839 SkBitmap wrap_texture(GrTexture* texture) { |
| 840 SkImageInfo info; |
| 841 texture->asImageInfo(&info); |
| 842 |
| 829 SkBitmap result; | 843 SkBitmap result; |
| 830 bool dummy; | 844 result.setConfig(info); |
| 831 SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy); | 845 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
| 832 result.setConfig(config, texture->width(), texture->height()); | |
| 833 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); | |
| 834 return result; | 846 return result; |
| 835 } | 847 } |
| 836 | 848 |
| 837 }; | 849 }; |
| 838 | 850 |
| 839 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 851 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 840 const SkPaint& paint, const SkMatrix* prePathMatrix, | 852 const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 841 bool pathIsMutable) { | 853 bool pathIsMutable) { |
| 842 CHECK_FOR_ANNOTATION(paint); | 854 CHECK_FOR_ANNOTATION(paint); |
| 843 CHECK_SHOULD_DRAW(draw, false); | 855 CHECK_SHOULD_DRAW(draw, false); |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 GrTexture* texture, | 1893 GrTexture* texture, |
| 1882 bool needClear) | 1894 bool needClear) |
| 1883 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1895 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| 1884 | 1896 |
| 1885 SkASSERT(texture && texture->asRenderTarget()); | 1897 SkASSERT(texture && texture->asRenderTarget()); |
| 1886 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1898 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
| 1887 // cache. We pass true for the third argument so that it will get unlocked. | 1899 // cache. We pass true for the third argument so that it will get unlocked. |
| 1888 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1900 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
| 1889 fNeedClear = needClear; | 1901 fNeedClear = needClear; |
| 1890 } | 1902 } |
| OLD | NEW |