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_surface(surface) | 84 , m_surface(surface) |
85 , m_contextProvider(contextProvider) | 85 , m_contextProvider(contextProvider) |
86 , m_imageBuffer(0) | 86 , m_imageBuffer(0) |
87 , m_msaaSampleCount(msaaSampleCount) | 87 , m_msaaSampleCount(msaaSampleCount) |
88 , m_bytesAllocated(0) | 88 , m_bytesAllocated(0) |
89 , m_didRecordDrawCommand(false) | 89 , m_didRecordDrawCommand(false) |
90 , m_isSurfaceValid(true) | 90 , m_isSurfaceValid(true) |
91 , m_framesPending(0) | 91 , m_framesPending(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_opacityMode(opacityMode) | 100 , m_opacityMode(opacityMode) |
99 { | 101 { |
100 ASSERT(m_canvas); | 102 ASSERT(m_canvas); |
101 ASSERT(m_surface); | 103 ASSERT(m_surface); |
102 ASSERT(m_contextProvider); | 104 ASSERT(m_contextProvider); |
103 // Used by browser tests to detect the use of a Canvas2DLayerBridge. | 105 // Used by browser tests to detect the use of a Canvas2DLayerBridge. |
104 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 106 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
105 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT extureLayer(this)); | 107 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExternalT extureLayer(this)); |
106 m_layer->setOpaque(opacityMode == Opaque); | 108 m_layer->setOpaque(opacityMode == Opaque); |
107 m_layer->setBlendBackgroundColor(opacityMode != Opaque); | 109 m_layer->setBlendBackgroundColor(opacityMode != Opaque); |
108 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 110 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
109 m_layer->setRateLimitContext(m_rateLimitingEnabled); | 111 m_layer->setRateLimitContext(m_rateLimitingEnabled); |
112 m_layer->setNearestNeighbor(m_filterLevel == SkPaint::kNone_FilterLevel); | |
110 m_canvas->setNotificationClient(this); | 113 m_canvas->setNotificationClient(this); |
111 #ifndef NDEBUG | 114 #ifndef NDEBUG |
112 canvas2DLayerBridgeInstanceCounter.increment(); | 115 canvas2DLayerBridgeInstanceCounter.increment(); |
113 #endif | 116 #endif |
114 } | 117 } |
115 | 118 |
116 Canvas2DLayerBridge::~Canvas2DLayerBridge() | 119 Canvas2DLayerBridge::~Canvas2DLayerBridge() |
117 { | 120 { |
118 ASSERT(m_destructionInProgress); | 121 ASSERT(m_destructionInProgress); |
119 ASSERT(!Canvas2DLayerManager::get().isInList(this)); | 122 ASSERT(!Canvas2DLayerManager::get().isInList(this)); |
(...skipping 20 matching lines...) Expand all Loading... | |
140 m_layer->clearTexture(); | 143 m_layer->clearTexture(); |
141 // Orphaning the layer is required to trigger the recration of a new layer | 144 // Orphaning the layer is required to trigger the recration of a new layer |
142 // in the case where destruction is caused by a canvas resize. Test: | 145 // in the case where destruction is caused by a canvas resize. Test: |
143 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html | 146 // virtual/gpu/fast/canvas/canvas-resize-after-paint-without-layout.html |
144 m_layer->layer()->removeFromParent(); | 147 m_layer->layer()->removeFromParent(); |
145 // To anyone who ever hits this assert: Please update crbug.com/344666 | 148 // To anyone who ever hits this assert: Please update crbug.com/344666 |
146 // with repro steps. | 149 // with repro steps. |
147 ASSERT(!m_bytesAllocated); | 150 ASSERT(!m_bytesAllocated); |
148 } | 151 } |
149 | 152 |
153 void Canvas2DLayerBridge::setFilterLevel(SkPaint::FilterLevel filterLevel) | |
154 { | |
155 ASSERT(!m_destructionInProgress); | |
156 if (m_filterLevel != filterLevel) { | |
esprehn
2014/12/16 19:22:32
Remove the old vs new check. setNearestNeighbor al
jackhou1
2014/12/17 01:28:09
Done.
| |
157 m_filterLevel = filterLevel; | |
158 m_layer->setNearestNeighbor(m_filterLevel == SkPaint::kNone_FilterLevel) ; | |
159 } | |
160 } | |
161 | |
150 void Canvas2DLayerBridge::setIsHidden(bool hidden) | 162 void Canvas2DLayerBridge::setIsHidden(bool hidden) |
151 { | 163 { |
152 ASSERT(!m_destructionInProgress); | 164 ASSERT(!m_destructionInProgress); |
153 bool newHiddenValue = hidden || m_destructionInProgress; | 165 bool newHiddenValue = hidden || m_destructionInProgress; |
154 if (m_isHidden == newHiddenValue) | 166 if (m_isHidden == newHiddenValue) |
155 return; | 167 return; |
156 | 168 |
157 m_isHidden = newHiddenValue; | 169 m_isHidden = newHiddenValue; |
158 if (isHidden()) { | 170 if (isHidden()) { |
159 freeTransientResources(); | 171 freeTransientResources(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 WebGraphicsContext3D* webContext = context(); | 366 WebGraphicsContext3D* webContext = context(); |
355 | 367 |
356 // Release to skia textures that were previouosly released by the | 368 // Release to skia textures that were previouosly released by the |
357 // compositor. We do this before acquiring the next snapshot in | 369 // compositor. We do this before acquiring the next snapshot in |
358 // order to cap maximum gpu memory consumption. | 370 // order to cap maximum gpu memory consumption. |
359 flush(); | 371 flush(); |
360 | 372 |
361 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); | 373 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); |
362 | 374 |
363 // Early exit if canvas was not drawn to since last prepareMailbox | 375 // Early exit if canvas was not drawn to since last prepareMailbox |
364 if (image->uniqueID() == m_lastImageId) | 376 GLenum filter = m_filterLevel == SkPaint::kNone_FilterLevel ? GL_NEAREST : G L_LINEAR; |
377 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter) | |
365 return false; | 378 return false; |
366 m_lastImageId = image->uniqueID(); | 379 m_lastImageId = image->uniqueID(); |
380 m_lastFilter = filter; | |
367 | 381 |
368 { | 382 { |
369 MailboxInfo tmp; | 383 MailboxInfo tmp; |
370 tmp.m_image = image; | 384 tmp.m_image = image; |
371 tmp.m_parentLayerBridge = this; | 385 tmp.m_parentLayerBridge = this; |
372 m_mailboxes.prepend(tmp); | 386 m_mailboxes.prepend(tmp); |
373 } | 387 } |
374 MailboxInfo& mailboxInfo = m_mailboxes.first(); | 388 MailboxInfo& mailboxInfo = m_mailboxes.first(); |
375 | 389 |
390 mailboxInfo.m_mailbox.nearestNeighbor = filter == GL_NEAREST; | |
391 | |
376 GrContext* grContext = m_contextProvider->grContext(); | 392 GrContext* grContext = m_contextProvider->grContext(); |
377 if (!grContext) | 393 if (!grContext) |
378 return true; // for testing: skip gl stuff when using a mock graphics co ntext. | 394 return true; // for testing: skip gl stuff when using a mock graphics co ntext. |
379 | 395 |
380 ASSERT(image->getTexture()); | 396 ASSERT(image->getTexture()); |
381 | 397 |
382 // Because of texture sharing with the compositor, we must invalidate | 398 // Because of texture sharing with the compositor, we must invalidate |
383 // the state cached in skia so that the deferred copy on write | 399 // the state cached in skia so that the deferred copy on write |
384 // in SkSurface_Gpu does not make any false assumptions. | 400 // in SkSurface_Gpu does not make any false assumptions. |
385 mailboxInfo.m_image->getTexture()->textureParamsModified(); | 401 mailboxInfo.m_image->getTexture()->textureParamsModified(); |
386 | 402 |
387 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo.m_image->getTexture()->ge tTextureHandle()); | 403 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo.m_image->getTexture()->ge tTextureHandle()); |
388 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 404 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
389 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 405 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
390 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); | 406 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); |
391 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); | 407 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); |
392 | 408 |
393 // Re-use the texture's existing mailbox, if there is one. | 409 // Re-use the texture's existing mailbox, if there is one. |
394 if (image->getTexture()->getCustomData()) { | 410 if (image->getTexture()->getCustomData()) { |
395 ASSERT(image->getTexture()->getCustomData()->size() == sizeof(mailboxInf o.m_mailbox.name)); | 411 ASSERT(image->getTexture()->getCustomData()->size() == sizeof(mailboxInf o.m_mailbox.name)); |
396 memcpy(&mailboxInfo.m_mailbox.name[0], image->getTexture()->getCustomDat a()->data(), sizeof(mailboxInfo.m_mailbox.name)); | 412 memcpy(&mailboxInfo.m_mailbox.name[0], image->getTexture()->getCustomDat a()->data(), sizeof(mailboxInfo.m_mailbox.name)); |
397 } else { | 413 } else { |
398 context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name); | 414 context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name); |
399 RefPtr<SkData> mialboxNameData = adoptRef(SkData::NewWithCopy(&mailboxIn fo.m_mailbox.name[0], sizeof(mailboxInfo.m_mailbox.name))); | 415 RefPtr<SkData> mialboxNameData = adoptRef(SkData::NewWithCopy(&mailboxIn fo.m_mailbox.name[0], sizeof(mailboxInfo.m_mailbox.name))); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 512 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
497 // This copy constructor should only be used for Deque::prepend | 513 // This copy constructor should only be used for Deque::prepend |
498 // Assuming 'other' is to be destroyed, we transfer m_image and | 514 // Assuming 'other' is to be destroyed, we transfer m_image and |
499 // m_parentLayerBridge ownership rather than do a refcount dance. | 515 // m_parentLayerBridge ownership rather than do a refcount dance. |
500 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 516 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
501 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); | 517 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); |
502 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); | 518 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); |
503 } | 519 } |
504 | 520 |
505 } // namespace blink | 521 } // namespace blink |
OLD | NEW |