Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 562583002: Implement image-rendering:pixelated for accelerated 2D canvases. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Don't call setImageInterpolationQuality Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/platform/graphics/Canvas2DLayerBridge.h ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 m_filterLevel = filterLevel;
157 m_layer->setNearestNeighbor(m_filterLevel == SkPaint::kNone_FilterLevel);
158 }
159
150 void Canvas2DLayerBridge::setIsHidden(bool hidden) 160 void Canvas2DLayerBridge::setIsHidden(bool hidden)
151 { 161 {
152 ASSERT(!m_destructionInProgress); 162 ASSERT(!m_destructionInProgress);
153 bool newHiddenValue = hidden || m_destructionInProgress; 163 bool newHiddenValue = hidden || m_destructionInProgress;
154 if (m_isHidden == newHiddenValue) 164 if (m_isHidden == newHiddenValue)
155 return; 165 return;
156 166
157 m_isHidden = newHiddenValue; 167 m_isHidden = newHiddenValue;
158 if (isHidden()) { 168 if (isHidden()) {
159 freeTransientResources(); 169 freeTransientResources();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 WebGraphicsContext3D* webContext = context(); 364 WebGraphicsContext3D* webContext = context();
355 365
356 // Release to skia textures that were previouosly released by the 366 // Release to skia textures that were previouosly released by the
357 // compositor. We do this before acquiring the next snapshot in 367 // compositor. We do this before acquiring the next snapshot in
358 // order to cap maximum gpu memory consumption. 368 // order to cap maximum gpu memory consumption.
359 flush(); 369 flush();
360 370
361 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot()); 371 RefPtr<SkImage> image = adoptRef(m_canvas->newImageSnapshot());
362 372
363 // Early exit if canvas was not drawn to since last prepareMailbox 373 // Early exit if canvas was not drawn to since last prepareMailbox
364 if (image->uniqueID() == m_lastImageId) 374 GLenum filter = m_filterLevel == SkPaint::kNone_FilterLevel ? GL_NEAREST : G L_LINEAR;
375 if (image->uniqueID() == m_lastImageId && filter == m_lastFilter)
365 return false; 376 return false;
366 m_lastImageId = image->uniqueID(); 377 m_lastImageId = image->uniqueID();
378 m_lastFilter = filter;
367 379
368 { 380 {
369 MailboxInfo tmp; 381 MailboxInfo tmp;
370 tmp.m_image = image; 382 tmp.m_image = image;
371 tmp.m_parentLayerBridge = this; 383 tmp.m_parentLayerBridge = this;
372 m_mailboxes.prepend(tmp); 384 m_mailboxes.prepend(tmp);
373 } 385 }
374 MailboxInfo& mailboxInfo = m_mailboxes.first(); 386 MailboxInfo& mailboxInfo = m_mailboxes.first();
375 387
388 mailboxInfo.m_mailbox.nearestNeighbor = filter == GL_NEAREST;
389
376 GrContext* grContext = m_contextProvider->grContext(); 390 GrContext* grContext = m_contextProvider->grContext();
377 if (!grContext) 391 if (!grContext)
378 return true; // for testing: skip gl stuff when using a mock graphics co ntext. 392 return true; // for testing: skip gl stuff when using a mock graphics co ntext.
379 393
380 ASSERT(image->getTexture()); 394 ASSERT(image->getTexture());
381 395
382 // Because of texture sharing with the compositor, we must invalidate 396 // Because of texture sharing with the compositor, we must invalidate
383 // the state cached in skia so that the deferred copy on write 397 // the state cached in skia so that the deferred copy on write
384 // in SkSurface_Gpu does not make any false assumptions. 398 // in SkSurface_Gpu does not make any false assumptions.
385 mailboxInfo.m_image->getTexture()->textureParamsModified(); 399 mailboxInfo.m_image->getTexture()->textureParamsModified();
386 400
387 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo.m_image->getTexture()->ge tTextureHandle()); 401 webContext->bindTexture(GL_TEXTURE_2D, mailboxInfo.m_image->getTexture()->ge tTextureHandle());
388 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 402 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
389 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 403 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
390 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); 404 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 ); 405 webContext->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
392 406
393 // Re-use the texture's existing mailbox, if there is one. 407 // Re-use the texture's existing mailbox, if there is one.
394 if (image->getTexture()->getCustomData()) { 408 if (image->getTexture()->getCustomData()) {
395 ASSERT(image->getTexture()->getCustomData()->size() == sizeof(mailboxInf o.m_mailbox.name)); 409 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)); 410 memcpy(&mailboxInfo.m_mailbox.name[0], image->getTexture()->getCustomDat a()->data(), sizeof(mailboxInfo.m_mailbox.name));
397 } else { 411 } else {
398 context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name); 412 context()->genMailboxCHROMIUM(mailboxInfo.m_mailbox.name);
399 RefPtr<SkData> mialboxNameData = adoptRef(SkData::NewWithCopy(&mailboxIn fo.m_mailbox.name[0], sizeof(mailboxInfo.m_mailbox.name))); 413 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
496 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { 510 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) {
497 // This copy constructor should only be used for Deque::prepend 511 // This copy constructor should only be used for Deque::prepend
498 // Assuming 'other' is to be destroyed, we transfer m_image and 512 // Assuming 'other' is to be destroyed, we transfer m_image and
499 // m_parentLayerBridge ownership rather than do a refcount dance. 513 // m_parentLayerBridge ownership rather than do a refcount dance.
500 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); 514 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox));
501 m_image = const_cast<MailboxInfo*>(&other)->m_image.release(); 515 m_image = const_cast<MailboxInfo*>(&other)->m_image.release();
502 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release(); 516 m_parentLayerBridge = const_cast<MailboxInfo*>(&other)->m_parentLayerBridge. release();
503 } 517 }
504 518
505 } // namespace blink 519 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/Canvas2DLayerBridge.h ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698