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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 fRenderTarget->ref(); | 207 fRenderTarget->ref(); |
208 | 208 |
209 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 209 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
210 // on the RT but not vice-versa. | 210 // on the RT but not vice-versa. |
211 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 211 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
212 // busting chrome (for a currently unknown reason). | 212 // busting chrome (for a currently unknown reason). |
213 GrSurface* surface = fRenderTarget->asTexture(); | 213 GrSurface* surface = fRenderTarget->asTexture(); |
214 if (NULL == surface) { | 214 if (NULL == surface) { |
215 surface = fRenderTarget; | 215 surface = fRenderTarget; |
216 } | 216 } |
217 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); | 217 |
| 218 SkImageInfo info; |
| 219 surface->asImageInfo(&info); |
| 220 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, cached)); |
218 | 221 |
219 this->setPixelRef(pr, 0)->unref(); | 222 this->setPixelRef(pr, 0)->unref(); |
220 } | 223 } |
221 | 224 |
222 SkGpuDevice::SkGpuDevice(GrContext* context, | 225 SkGpuDevice::SkGpuDevice(GrContext* context, |
223 SkBitmap::Config config, | 226 SkBitmap::Config config, |
224 int width, | 227 int width, |
225 int height, | 228 int height, |
226 int sampleCount) | 229 int sampleCount) |
227 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) { | 230 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) |
228 | 231 { |
229 fDrawProcs = NULL; | 232 fDrawProcs = NULL; |
230 | 233 |
231 fContext = context; | 234 fContext = context; |
232 fContext->ref(); | 235 fContext->ref(); |
233 | 236 |
234 fRenderTarget = NULL; | 237 fRenderTarget = NULL; |
235 fNeedClear = false; | 238 fNeedClear = false; |
236 | 239 |
237 if (config != SkBitmap::kRGB_565_Config) { | 240 if (config != SkBitmap::kRGB_565_Config) { |
238 config = SkBitmap::kARGB_8888_Config; | 241 config = SkBitmap::kARGB_8888_Config; |
239 } | 242 } |
240 | 243 |
241 GrTextureDesc desc; | 244 GrTextureDesc desc; |
242 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 245 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
243 desc.fWidth = width; | 246 desc.fWidth = width; |
244 desc.fHeight = height; | 247 desc.fHeight = height; |
245 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 248 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); |
246 desc.fSampleCnt = sampleCount; | 249 desc.fSampleCnt = sampleCount; |
247 | 250 |
| 251 SkImageInfo info; |
| 252 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { |
| 253 sk_throw(); |
| 254 } |
| 255 info.fWidth = width; |
| 256 info.fHeight = height; |
| 257 info.fAlphaType = kPremul_SkAlphaType; |
| 258 |
248 SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL,
0)); | 259 SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL,
0)); |
249 | 260 |
250 if (NULL != texture) { | 261 if (NULL != texture) { |
251 fRenderTarget = texture->asRenderTarget(); | 262 fRenderTarget = texture->asRenderTarget(); |
252 fRenderTarget->ref(); | 263 fRenderTarget->ref(); |
253 | 264 |
254 SkASSERT(NULL != fRenderTarget); | 265 SkASSERT(NULL != fRenderTarget); |
255 | 266 |
256 // wrap the bitmap with a pixelref to expose our texture | 267 // wrap the bitmap with a pixelref to expose our texture |
257 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (texture)); | 268 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); |
258 this->setPixelRef(pr, 0)->unref(); | 269 this->setPixelRef(pr, 0)->unref(); |
259 } else { | 270 } else { |
260 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", | 271 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", |
261 width, height); | 272 width, height); |
262 SkASSERT(false); | 273 SkASSERT(false); |
263 } | 274 } |
264 } | 275 } |
265 | 276 |
266 SkGpuDevice::~SkGpuDevice() { | 277 SkGpuDevice::~SkGpuDevice() { |
267 if (fDrawProcs) { | 278 if (fDrawProcs) { |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 844 |
834 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. | 845 // Draw the mask into maskTexture with the path's top-left at the origin usi
ng tempPaint. |
835 SkMatrix translate; | 846 SkMatrix translate; |
836 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); | 847 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); |
837 am.set(context, translate); | 848 am.set(context, translate); |
838 context->drawPath(tempPaint, devPath, stroke); | 849 context->drawPath(tempPaint, devPath, stroke); |
839 return true; | 850 return true; |
840 } | 851 } |
841 | 852 |
842 SkBitmap wrap_texture(GrTexture* texture) { | 853 SkBitmap wrap_texture(GrTexture* texture) { |
| 854 SkImageInfo info; |
| 855 texture->asImageInfo(&info); |
| 856 |
843 SkBitmap result; | 857 SkBitmap result; |
844 bool dummy; | 858 result.setConfig(info); |
845 SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy); | 859 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
846 result.setConfig(config, texture->width(), texture->height()); | |
847 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); | |
848 return result; | 860 return result; |
849 } | 861 } |
850 | 862 |
851 }; | 863 }; |
852 | 864 |
853 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 865 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
854 const SkPaint& paint, const SkMatrix* prePathMatrix, | 866 const SkPaint& paint, const SkMatrix* prePathMatrix, |
855 bool pathIsMutable) { | 867 bool pathIsMutable) { |
856 CHECK_FOR_ANNOTATION(paint); | 868 CHECK_FOR_ANNOTATION(paint); |
857 CHECK_SHOULD_DRAW(draw, false); | 869 CHECK_SHOULD_DRAW(draw, false); |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 GrTexture* texture, | 1912 GrTexture* texture, |
1901 bool needClear) | 1913 bool needClear) |
1902 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1914 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1903 | 1915 |
1904 SkASSERT(texture && texture->asRenderTarget()); | 1916 SkASSERT(texture && texture->asRenderTarget()); |
1905 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1917 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1906 // cache. We pass true for the third argument so that it will get unlocked. | 1918 // cache. We pass true for the third argument so that it will get unlocked. |
1907 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1919 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1908 fNeedClear = needClear; | 1920 fNeedClear = needClear; |
1909 } | 1921 } |
OLD | NEW |