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/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 config = config8888_to_grconfig_and_flags(config8888, &flags); | 337 config = config8888_to_grconfig_and_flags(config8888, &flags); |
338 } else { | 338 } else { |
339 flags = 0; | 339 flags = 0; |
340 config= SkBitmapConfig2GrPixelConfig(bitmap.config()); | 340 config= SkBitmapConfig2GrPixelConfig(bitmap.config()); |
341 } | 341 } |
342 | 342 |
343 fRenderTarget->writePixels(x, y, bitmap.width(), bitmap.height(), | 343 fRenderTarget->writePixels(x, y, bitmap.width(), bitmap.height(), |
344 config, bitmap.getPixels(), bitmap.rowBytes(), fl
ags); | 344 config, bitmap.getPixels(), bitmap.rowBytes(), fl
ags); |
345 } | 345 } |
346 | 346 |
347 namespace { | |
348 void purgeClipCB(int genID, void* ) { | |
349 | |
350 if (SkClipStack::kInvalidGenID == genID || | |
351 SkClipStack::kEmptyGenID == genID || | |
352 SkClipStack::kWideOpenGenID == genID) { | |
353 // none of these cases will have a cached clip mask | |
354 return; | |
355 } | |
356 | |
357 } | |
358 }; | |
359 | |
360 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { | 347 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
361 INHERITED::onAttachToCanvas(canvas); | 348 INHERITED::onAttachToCanvas(canvas); |
362 | 349 |
363 // Canvas promises that this ptr is valid until onDetachFromCanvas is called | 350 // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
364 fClipData.fClipStack = canvas->getClipStack(); | 351 fClipData.fClipStack = canvas->getClipStack(); |
365 | |
366 fClipData.fClipStack->addPurgeClipCallback(purgeClipCB, fContext); | |
367 } | 352 } |
368 | 353 |
369 void SkGpuDevice::onDetachFromCanvas() { | 354 void SkGpuDevice::onDetachFromCanvas() { |
370 INHERITED::onDetachFromCanvas(); | 355 INHERITED::onDetachFromCanvas(); |
371 | |
372 // TODO: iterate through the clip stack and clean up any cached clip masks | |
373 fClipData.fClipStack->removePurgeClipCallback(purgeClipCB, fContext); | |
374 | |
375 fClipData.fClipStack = NULL; | 356 fClipData.fClipStack = NULL; |
376 } | 357 } |
377 | 358 |
378 // call this every draw call, to ensure that the context reflects our state, | 359 // call this every draw call, to ensure that the context reflects our state, |
379 // and not the state from some other canvas/device | 360 // and not the state from some other canvas/device |
380 void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) { | 361 void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) { |
381 SkASSERT(NULL != fClipData.fClipStack); | 362 SkASSERT(NULL != fClipData.fClipStack); |
382 | 363 |
383 fContext->setRenderTarget(fRenderTarget); | 364 fContext->setRenderTarget(fRenderTarget); |
384 | 365 |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 GrTexture* texture, | 1832 GrTexture* texture, |
1852 bool needClear) | 1833 bool needClear) |
1853 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1834 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1854 | 1835 |
1855 SkASSERT(texture && texture->asRenderTarget()); | 1836 SkASSERT(texture && texture->asRenderTarget()); |
1856 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1837 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1857 // cache. We pass true for the third argument so that it will get unlocked. | 1838 // cache. We pass true for the third argument so that it will get unlocked. |
1858 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1839 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1859 fNeedClear = needClear; | 1840 fNeedClear = needClear; |
1860 } | 1841 } |
OLD | NEW |