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