OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 , m_contextProvider(contextProvider) | 81 , m_contextProvider(contextProvider) |
82 , m_imageBuffer(0) | 82 , m_imageBuffer(0) |
83 , m_msaaSampleCount(msaaSampleCount) | 83 , m_msaaSampleCount(msaaSampleCount) |
84 , m_bytesAllocated(0) | 84 , m_bytesAllocated(0) |
85 , m_didRecordDrawCommand(false) | 85 , m_didRecordDrawCommand(false) |
86 , m_isSurfaceValid(true) | 86 , m_isSurfaceValid(true) |
87 , m_framesPending(0) | 87 , m_framesPending(0) |
88 , m_framesSinceMailboxRelease(0) | 88 , m_framesSinceMailboxRelease(0) |
89 , m_destructionInProgress(false) | 89 , m_destructionInProgress(false) |
90 , m_rateLimitingEnabled(false) | 90 , m_rateLimitingEnabled(false) |
| 91 , m_filterLevel(SkPaint::kLow_FilterLevel) |
91 , m_isHidden(false) | 92 , m_isHidden(false) |
92 , m_next(0) | 93 , m_next(0) |
93 , m_prev(0) | 94 , m_prev(0) |
94 , m_lastImageId(0) | 95 , m_lastImageId(0) |
| 96 , m_lastFilter(GL_LINEAR) |
95 , m_releasedMailboxInfoIndex(InvalidMailboxIndex) | 97 , m_releasedMailboxInfoIndex(InvalidMailboxIndex) |
96 { | 98 { |
97 ASSERT(m_canvas); | 99 ASSERT(m_canvas); |
98 ASSERT(m_surface); | 100 ASSERT(m_surface); |
99 ASSERT(m_contextProvider); | 101 ASSERT(m_contextProvider); |
100 // Used by browser tests to detect the use of a Canvas2DLayerBridge. | 102 // Used by browser tests to detect the use of a Canvas2DLayerBridge. |
101 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 103 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
102 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT
extureLayer(this)); | 104 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT
extureLayer(this)); |
103 m_layer->setOpaque(opacityMode == Opaque); | 105 m_layer->setOpaque(opacityMode == Opaque); |
104 m_layer->setBlendBackgroundColor(opacityMode != Opaque); | 106 m_layer->setBlendBackgroundColor(opacityMode != Opaque); |
105 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 107 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
106 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 108 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
| 109 m_layer->setNearestNeighbor(m_filterLevel == SkPaint::kNone_FilterLevel); |
107 m_canvas->setNotificationClient(this); | 110 m_canvas->setNotificationClient(this); |
108 #ifndef NDEBUG | 111 #ifndef NDEBUG |
109 canvas2DLayerBridgeInstanceCounter.increment(); | 112 canvas2DLayerBridgeInstanceCounter.increment(); |
110 #endif | 113 #endif |
111 } | 114 } |
112 | 115 |
113 Canvas2DLayerBridge::~Canvas2DLayerBridge() | 116 Canvas2DLayerBridge::~Canvas2DLayerBridge() |
114 { | 117 { |
115 ASSERT(m_destructionInProgress); | 118 ASSERT(m_destructionInProgress); |
116 ASSERT(!Canvas2DLayerManager::get().isInList(this)); | 119 ASSERT(!Canvas2DLayerManager::get().isInList(this)); |
(...skipping 28 matching lines...) Expand all Loading... |
145 m_layer->clearTexture(); | 148 m_layer->clearTexture(); |
146 // Orphaning the layer is required to trigger the recration of a new layer | 149 // Orphaning the layer is required to trigger the recration of a new layer |
147 // in the case where destruction is caused by a canvas resize. Test: | 150 // in the case where destruction is caused by a canvas resize. Test: |
148 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html | 151 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
149 m_layer->layer()->removeFromParent(); | 152 m_layer->layer()->removeFromParent(); |
150 // To anyone who ever hits this assert: Please update crbug.com/344666 | 153 // To anyone who ever hits this assert: Please update crbug.com/344666 |
151 // with repro steps. | 154 // with repro steps. |
152 ASSERT(!m_bytesAllocated); | 155 ASSERT(!m_bytesAllocated); |
153 } | 156 } |
154 | 157 |
| 158 void Canvas2DLayerBridge::setFilterLevel(SkPaint::FilterLevel filterLevel) |
| 159 { |
| 160 ASSERT(!m_destructionInProgress); |
| 161 if (m_filterLevel != filterLevel) { |
| 162 m_filterLevel = filterLevel; |
| 163 m_layer->setNearestNeighbor(m_filterLevel == SkPaint::kNone_FilterLevel)
; |
| 164 m_imageBuffer->notifySurfaceInvalid(); |
| 165 } |
| 166 } |
| 167 |
155 void Canvas2DLayerBridge::setIsHidden(bool hidden) | 168 void Canvas2DLayerBridge::setIsHidden(bool hidden) |
156 { | 169 { |
157 ASSERT(!m_destructionInProgress); | 170 ASSERT(!m_destructionInProgress); |
158 bool newHiddenValue = hidden || m_destructionInProgress; | 171 bool newHiddenValue = hidden || m_destructionInProgress; |
159 if (m_isHidden == newHiddenValue) | 172 if (m_isHidden == newHiddenValue) |
160 return; | 173 return; |
161 | 174 |
162 m_isHidden = newHiddenValue; | 175 m_isHidden = newHiddenValue; |
163 if (isHidden()) { | 176 if (isHidden()) { |
164 freeTransientResources(); | 177 freeTransientResources(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 WebGraphicsContext3D* webContext = context(); | 420 WebGraphicsContext3D* webContext = context(); |
408 | 421 |
409 // Release to skia textures that were previouosly released by the | 422 // Release to skia textures that were previouosly released by the |
410 // compositor. We do this before acquiring the next snapshot in | 423 // compositor. We do this before acquiring the next snapshot in |
411 // order to cap maximum gpu memory consumption. | 424 // order to cap maximum gpu memory consumption. |
412 flush(); | 425 flush(); |
413 | 426 |
414 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); | 427 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); |
415 | 428 |
416 // Early exit if canvas was not drawn to since last prepareMailbox | 429 // Early exit if canvas was not drawn to since last prepareMailbox |
417 if (image->uniqueID() == m_lastImageId) | 430 GLenum filter = m_filterLevel == SkPaint::kNone_FilterLevel ? GL_NEAREST : G
L_LINEAR; |
| 431 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) |
418 return false; | 432 return false; |
419 m_lastImageId = image->uniqueID(); | 433 m_lastImageId = image->uniqueID(); |
420 | 434 |
421 MailboxInfo* mailboxInfo = createMailboxInfo(); | 435 MailboxInfo* mailboxInfo = createMailboxInfo(); |
422 mailboxInfo->m_status = MailboxInUse; | 436 mailboxInfo->m_status = MailboxInUse; |
423 mailboxInfo->m_image = image; | 437 mailboxInfo->m_image = image; |
424 | 438 |
425 ASSERT(mailboxInfo->m_mailbox.syncPoint == 0); | 439 ASSERT(mailboxInfo->m_mailbox.syncPoint == 0); |
426 ASSERT(mailboxInfo->m_image.get()); | 440 ASSERT(mailboxInfo->m_image.get()); |
427 | 441 |
428 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has | 442 // set m_parentLayerBridge to make sure 'this' stays alive as long as it has |
429 // live mailboxes | 443 // live mailboxes |
430 ASSERT(!mailboxInfo->m_parentLayerBridge); | 444 ASSERT(!mailboxInfo->m_parentLayerBridge); |
431 mailboxInfo->m_parentLayerBridge = this; | 445 mailboxInfo->m_parentLayerBridge = this; |
432 *outMailbox = mailboxInfo->m_mailbox; | 446 *outMailbox = mailboxInfo->m_mailbox; |
433 | 447 |
| 448 mailboxInfo->m_mailbox.nearestNeighbor = filter == GL_NEAREST; |
| 449 |
434 GrContext* grContext = m_contextProvider->grContext(); | 450 GrContext* grContext = m_contextProvider->grContext(); |
435 if (!grContext) | 451 if (!grContext) |
436 return true; // for testing: skip gl stuff when using a mock graphics co
ntext. | 452 return true; // for testing: skip gl stuff when using a mock graphics co
ntext. |
437 | 453 |
438 ASSERT(mailboxInfo->m_image->getTexture()); | 454 ASSERT(mailboxInfo->m_image->getTexture()); |
439 | 455 |
440 // Because of texture sharing with the compositor, we must invalidate | 456 // Because of texture sharing with the compositor, we must invalidate |
441 // the state cached in skia so that the deferred copy on write | 457 // the state cached in skia so that the deferred copy on write |
442 // in SkSurface_Gpu does not make any false assumptions. | 458 // in SkSurface_Gpu does not make any false assumptions. |
443 mailboxInfo->m_image->getTexture()->textureParamsModified(); | 459 mailboxInfo->m_image->getTexture()->textureParamsModified(); |
444 | 460 |
445 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g
etTextureHandle()); | 461 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g
etTextureHandle()); |
446 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 462 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
447 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 463 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
448 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
); | 464 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
); |
449 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
); | 465 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
); |
450 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam
e); | 466 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam
e); |
451 if (isHidden()) { | 467 if (isHidden()) { |
452 // With hidden canvases, we release the SkImage immediately because | 468 // With hidden canvases, we release the SkImage immediately because |
453 // there is no need for animations to be double buffered. | 469 // there is no need for animations to be double buffered. |
454 mailboxInfo->m_image.clear(); | 470 mailboxInfo->m_image.clear(); |
455 } else { | 471 } else { |
456 webContext->flush(); | 472 webContext->flush(); |
457 mailboxInfo->m_mailbox.syncPoint = webContext->insertSyncPoint(); | 473 mailboxInfo->m_mailbox.syncPoint = webContext->insertSyncPoint(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 // This copy constructor should only be used for Vector reallocation | 606 // This copy constructor should only be used for Vector reallocation |
591 // Assuming 'other' is to be destroyed, we transfer m_image and | 607 // Assuming 'other' is to be destroyed, we transfer m_image and |
592 // m_parentLayerBridge ownership rather than do a refcount dance. | 608 // m_parentLayerBridge ownership rather than do a refcount dance. |
593 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 609 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
594 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 610 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
595 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge.
release(); | 611 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge.
release(); |
596 m_status = other.m_status; | 612 m_status = other.m_status; |
597 } | 613 } |
598 | 614 |
599 } // namespace blink | 615 } // namespace blink |
OLD | NEW |