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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), | 176 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), |
177 info.width(), info.height(), flags
)); | 177 info.width(), info.height(), flags
)); |
178 } | 178 } |
179 | 179 |
180 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) | 180 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) |
181 : INHERITED(drawContext->surfaceProps()) | 181 : INHERITED(drawContext->surfaceProps()) |
182 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) | 182 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) |
183 , fRenderTarget(drawContext->renderTarget()) | 183 , fRenderTarget(drawContext->renderTarget()) |
184 , fDrawContext(std::move(drawContext)) { | 184 , fDrawContext(std::move(drawContext)) { |
| 185 fSize.set(width, height); |
185 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 186 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
186 | 187 |
187 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | |
188 SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(width, heigh
t); | |
189 SkPixelRef* pr = new SkGrPixelRef(info, fRenderTarget.get()); | |
190 fLegacyBitmap.setInfo(info); | |
191 fLegacyBitmap.setPixelRef(pr)->unref(); | |
192 | |
193 if (flags & kNeedClear_Flag) { | 188 if (flags & kNeedClear_Flag) { |
194 this->clearAll(); | 189 this->clearAll(); |
195 } | 190 } |
196 } | 191 } |
197 | 192 |
198 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, | 193 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, |
199 SkBudgeted budgeted, | 194 SkBudgeted budgeted, |
200 const SkImageInfo& origInfo, | 195 const SkImageInfo& origInfo, |
201 int sampleCount, | 196 int sampleCount, |
202 const SkSurfaceProps* surfac
eProps) { | 197 const SkSurfaceProps* surfac
eProps) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); | 272 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); |
278 if (kUnknown_GrPixelConfig == config) { | 273 if (kUnknown_GrPixelConfig == config) { |
279 return false; | 274 return false; |
280 } | 275 } |
281 uint32_t flags = 0; | 276 uint32_t flags = 0; |
282 if (kUnpremul_SkAlphaType == info.alphaType()) { | 277 if (kUnpremul_SkAlphaType == info.alphaType()) { |
283 flags = GrContext::kUnpremul_PixelOpsFlag; | 278 flags = GrContext::kUnpremul_PixelOpsFlag; |
284 } | 279 } |
285 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); | 280 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); |
286 | 281 |
287 // need to bump our genID for compatibility with clients that "know" we have
a bitmap | |
288 fLegacyBitmap.notifyPixelsChanged(); | |
289 | |
290 return true; | 282 return true; |
291 } | 283 } |
292 | 284 |
293 const SkBitmap& SkGpuDevice::onAccessBitmap() { | |
294 ASSERT_SINGLE_OWNER | |
295 return fLegacyBitmap; | |
296 } | |
297 | |
298 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { | 285 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
299 ASSERT_SINGLE_OWNER | 286 ASSERT_SINGLE_OWNER |
300 // For compatibility with clients the know we're backed w/ a bitmap, and wan
t to inspect its | |
301 // genID. When we can hide/remove that fact, we can eliminate this call to n
otify. | |
302 // ... ugh. | |
303 fLegacyBitmap.notifyPixelsChanged(); | |
304 return false; | 287 return false; |
305 } | 288 } |
306 | 289 |
307 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { | 290 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
308 ASSERT_SINGLE_OWNER | 291 ASSERT_SINGLE_OWNER |
309 INHERITED::onAttachToCanvas(canvas); | 292 INHERITED::onAttachToCanvas(canvas); |
310 | 293 |
311 // Canvas promises that this ptr is valid until onDetachFromCanvas is called | 294 // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
312 fClipStack.reset(SkRef(canvas->getClipStack())); | 295 fClipStack.reset(SkRef(canvas->getClipStack())); |
313 } | 296 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 346 } |
364 newDC->copySurface(fDrawContext->asTexture().get(), | 347 newDC->copySurface(fDrawContext->asTexture().get(), |
365 SkIRect::MakeWH(this->width(), this->height()), | 348 SkIRect::MakeWH(this->width(), this->height()), |
366 SkIPoint::Make(0, 0)); | 349 SkIPoint::Make(0, 0)); |
367 } | 350 } |
368 | 351 |
369 SkASSERT(fDrawContext->accessRenderTarget() != newDC->accessRenderTarget()); | 352 SkASSERT(fDrawContext->accessRenderTarget() != newDC->accessRenderTarget()); |
370 | 353 |
371 fRenderTarget = newDC->renderTarget(); | 354 fRenderTarget = newDC->renderTarget(); |
372 | 355 |
373 #ifdef SK_DEBUG | |
374 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | |
375 kPremul_SkAlp
haType); | |
376 SkASSERT(info == fLegacyBitmap.info()); | |
377 #endif | |
378 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget.get())
; | |
379 fLegacyBitmap.setPixelRef(pr)->unref(); | |
380 | |
381 fDrawContext = newDC; | 356 fDrawContext = newDC; |
382 } | 357 } |
383 | 358 |
384 /////////////////////////////////////////////////////////////////////////////// | 359 /////////////////////////////////////////////////////////////////////////////// |
385 | 360 |
386 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 361 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
387 ASSERT_SINGLE_OWNER | 362 ASSERT_SINGLE_OWNER |
388 CHECK_SHOULD_DRAW(draw); | 363 CHECK_SHOULD_DRAW(draw); |
389 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); | 364 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); |
390 | 365 |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 } | 1866 } |
1892 | 1867 |
1893 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1868 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1894 ASSERT_SINGLE_OWNER | 1869 ASSERT_SINGLE_OWNER |
1895 // We always return a transient cache, so it is freed after each | 1870 // We always return a transient cache, so it is freed after each |
1896 // filter traversal. | 1871 // filter traversal. |
1897 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1872 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1898 } | 1873 } |
1899 | 1874 |
1900 #endif | 1875 #endif |
OLD | NEW |