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) |
95 , m_releasedMailboxInfoIndex(InvalidMailboxIndex) | 96 , m_releasedMailboxInfoIndex(InvalidMailboxIndex) |
96 { | 97 { |
97 ASSERT(m_canvas); | 98 ASSERT(m_canvas); |
98 ASSERT(m_surface); | 99 ASSERT(m_surface); |
99 ASSERT(m_contextProvider); | 100 ASSERT(m_contextProvider); |
100 // Used by browser tests to detect the use of a Canvas2DLayerBridge. | 101 // Used by browser tests to detect the use of a Canvas2DLayerBridge. |
101 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 102 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
102 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT extureLayer(this)); | 103 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT extureLayer(this)); |
103 m_layer->setOpaque(opacityMode == Opaque); | 104 m_layer->setOpaque(opacityMode == Opaque); |
104 m_layer->setBlendBackgroundColor(opacityMode != Opaque); | 105 m_layer->setBlendBackgroundColor(opacityMode != Opaque); |
105 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 106 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
106 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 107 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
108 m_layer->setFilterLevel(m_filterLevel); | |
107 m_canvas->setNotificationClient(this); | 109 m_canvas->setNotificationClient(this); |
108 #ifndef NDEBUG | 110 #ifndef NDEBUG |
109 canvas2DLayerBridgeInstanceCounter.increment(); | 111 canvas2DLayerBridgeInstanceCounter.increment(); |
110 #endif | 112 #endif |
111 } | 113 } |
112 | 114 |
113 Canvas2DLayerBridge::~Canvas2DLayerBridge() | 115 Canvas2DLayerBridge::~Canvas2DLayerBridge() |
114 { | 116 { |
115 ASSERT(m_destructionInProgress); | 117 ASSERT(m_destructionInProgress); |
116 ASSERT(!Canvas2DLayerManager::get().isInList(this)); | 118 ASSERT(!Canvas2DLayerManager::get().isInList(this)); |
(...skipping 28 matching lines...) Expand all Loading... | |
145 m_layer->clearTexture(); | 147 m_layer->clearTexture(); |
146 // Orphaning the layer is required to trigger the recration of a new layer | 148 // 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: | 149 // in the case where destruction is caused by a canvas resize. Test: |
148 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html | 150 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
149 m_layer->layer()->removeFromParent(); | 151 m_layer->layer()->removeFromParent(); |
150 // To anyone who ever hits this assert: Please update crbug.com/344666 | 152 // To anyone who ever hits this assert: Please update crbug.com/344666 |
151 // with repro steps. | 153 // with repro steps. |
152 ASSERT(!m_bytesAllocated); | 154 ASSERT(!m_bytesAllocated); |
153 } | 155 } |
154 | 156 |
157 void Canvas2DLayerBridge::setFilterLevel(SkPaint::FilterLevel filterLevel) | |
158 { | |
159 printf("Canvas2dLayerBridge::setFilterLevel %d\n", filterLevel); | |
Justin Novosad
2014/10/28 20:27:44
Don't commit this line.
jackhou1
2014/10/29 00:56:39
Sorry. I'll remove all these before asking for a f
| |
160 ASSERT(!m_destructionInProgress); | |
161 if (m_filterLevel != filterLevel) { | |
162 m_filterLevel = filterLevel; | |
163 m_layer->setFilterLevel(m_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 |
434 GrContext* grContext = m_contextProvider->grContext(); | 448 GrContext* grContext = m_contextProvider->grContext(); |
435 if (!grContext) | 449 if (!grContext) |
436 return true; // for testing: skip gl stuff when using a mock graphics co ntext. | 450 return true; // for testing: skip gl stuff when using a mock graphics co ntext. |
437 | 451 |
438 ASSERT(mailboxInfo->m_image->getTexture()); | 452 ASSERT(mailboxInfo->m_image->getTexture()); |
439 | 453 |
440 // Because of texture sharing with the compositor, we must invalidate | 454 // Because of texture sharing with the compositor, we must invalidate |
441 // the state cached in skia so that the deferred copy on write | 455 // the state cached in skia so that the deferred copy on write |
442 // in SkSurface_Gpu does not make any false assumptions. | 456 // in SkSurface_Gpu does not make any false assumptions. |
443 mailboxInfo->m_image->getTexture()->textureParamsModified(); | 457 mailboxInfo->m_image->getTexture()->textureParamsModified(); |
444 | 458 |
445 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g etTextureHandle()); | 459 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo->m_image->getTexture()->g etTextureHandle()); |
446 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 460 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
447 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 461 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
Justin Novosad
2014/10/28 20:27:44
Does this even matter?
jackhou1
2014/10/29 00:56:39
Without this change, a pixelated canvas is intiall
| |
448 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); | 462 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 ); | 463 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); |
450 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam e); | 464 webContext->produceTextureCHROMIUM(GL_TEXTURE_2D, mailboxInfo->m_mailbox.nam e); |
451 if (isHidden()) { | 465 if (isHidden()) { |
452 // With hidden canvases, we release the SkImage immediately because | 466 // With hidden canvases, we release the SkImage immediately because |
453 // there is no need for animations to be double buffered. | 467 // there is no need for animations to be double buffered. |
454 mailboxInfo->m_image.clear(); | 468 mailboxInfo->m_image.clear(); |
455 } else { | 469 } else { |
456 webContext->flush(); | 470 webContext->flush(); |
457 mailboxInfo->m_mailbox.syncPoint = webContext->insertSyncPoint(); | 471 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 | 604 // This copy constructor should only be used for Vector reallocation |
591 // Assuming 'other' is to be destroyed, we transfer m_image and | 605 // Assuming 'other' is to be destroyed, we transfer m_image and |
592 // m_parentLayerBridge ownership rather than do a refcount dance. | 606 // m_parentLayerBridge ownership rather than do a refcount dance. |
593 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 607 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
594 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 608 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
595 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); | 609 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); |
596 m_status = other.m_status; | 610 m_status = other.m_status; |
597 } | 611 } |
598 | 612 |
599 } // namespace blink | 613 } // namespace blink |
OLD | NEW |