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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp

Issue 2559013002: Add ColorBehavior to blink::Image draw methods (Closed)
Patch Set: Rebase Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" 5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
6 6
7 #include "cc/output/compositor_frame.h" 7 #include "cc/output/compositor_frame.h"
8 #include "cc/quads/texture_draw_quad.h" 8 #include "cc/quads/texture_draw_quad.h"
9 #include "gpu/command_buffer/client/gles2_interface.h" 9 #include "gpu/command_buffer/client/gles2_interface.h"
10 #include "platform/CrossThreadFunctional.h" 10 #include "platform/CrossThreadFunctional.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (!bitmap) 63 if (!bitmap)
64 return; 64 return;
65 unsigned char* pixels = bitmap->pixels(); 65 unsigned char* pixels = bitmap->pixels();
66 DCHECK(pixels); 66 DCHECK(pixels);
67 SkImageInfo imageInfo = SkImageInfo::Make( 67 SkImageInfo imageInfo = SkImageInfo::Make(
68 m_width, m_height, kN32_SkColorType, 68 m_width, m_height, kN32_SkColorType,
69 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); 69 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
70 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456. 70 // TODO(xlai): Optimize to avoid copying pixels. See crbug.com/651456.
71 // However, in the case when |image| is texture backed, this function call 71 // However, in the case when |image| is texture backed, this function call
72 // does a GPU readback which is required. 72 // does a GPU readback which is required.
73 image->imageForCurrentFrame()->readPixels(imageInfo, pixels, 73 // TODO(ccameron): Canvas should produce sRGB images.
74 imageInfo.minRowBytes(), 0, 0); 74 // https://crbug.com/672299
75 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget())
76 ->readPixels(imageInfo, pixels, imageInfo.minRowBytes(), 0, 0);
75 resource.mailbox_holder.mailbox = bitmap->id(); 77 resource.mailbox_holder.mailbox = bitmap->id();
76 resource.mailbox_holder.texture_target = 0; 78 resource.mailbox_holder.texture_target = 0;
77 resource.is_software = true; 79 resource.is_software = true;
78 80
79 // Hold ref to |bitmap|, to keep it alive until the browser ReclaimResources. 81 // Hold ref to |bitmap|, to keep it alive until the browser ReclaimResources.
80 // It guarantees that the shared bitmap is not re-used or deleted. 82 // It guarantees that the shared bitmap is not re-used or deleted.
81 m_sharedBitmaps.add(m_nextResourceId, std::move(bitmap)); 83 m_sharedBitmaps.add(m_nextResourceId, std::move(bitmap));
82 } 84 }
83 85
84 void OffscreenCanvasFrameDispatcherImpl:: 86 void OffscreenCanvasFrameDispatcherImpl::
(...skipping 13 matching lines...) Expand all
98 SkImageInfo info = SkImageInfo::Make( 100 SkImageInfo info = SkImageInfo::Make(
99 m_width, m_height, kN32_SkColorType, 101 m_width, m_height, kN32_SkColorType,
100 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); 102 image->isPremultiplied() ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
101 RefPtr<ArrayBuffer> dstBuffer = 103 RefPtr<ArrayBuffer> dstBuffer =
102 ArrayBuffer::createOrNull(m_width * m_height, info.bytesPerPixel()); 104 ArrayBuffer::createOrNull(m_width * m_height, info.bytesPerPixel());
103 // If it fails to create a buffer for copying the pixel data, then exit early. 105 // If it fails to create a buffer for copying the pixel data, then exit early.
104 if (!dstBuffer) 106 if (!dstBuffer)
105 return; 107 return;
106 RefPtr<Uint8Array> dstPixels = 108 RefPtr<Uint8Array> dstPixels =
107 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); 109 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength());
108 image->imageForCurrentFrame()->readPixels(info, dstPixels->data(), 110 // TODO(ccameron): Canvas should produce sRGB images.
109 info.minRowBytes(), 0, 0); 111 // https://crbug.com/672299
112 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget())
113 ->readPixels(info, dstPixels->data(), info.minRowBytes(), 0, 0);
110 114
111 GLuint textureId = 0u; 115 GLuint textureId = 0u;
112 gl->GenTextures(1, &textureId); 116 gl->GenTextures(1, &textureId);
113 gl->BindTexture(GL_TEXTURE_2D, textureId); 117 gl->BindTexture(GL_TEXTURE_2D, textureId);
114 GLenum format = 118 GLenum format =
115 (kN32_SkColorType == kRGBA_8888_SkColorType) ? GL_RGBA : GL_BGRA_EXT; 119 (kN32_SkColorType == kRGBA_8888_SkColorType) ? GL_RGBA : GL_BGRA_EXT;
116 gl->TexImage2D(GL_TEXTURE_2D, 0, format, m_width, m_height, 0, format, 120 gl->TexImage2D(GL_TEXTURE_2D, 0, format, m_width, m_height, 0, format,
117 GL_UNSIGNED_BYTE, 0); 121 GL_UNSIGNED_BYTE, 0);
118 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 122 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
119 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 123 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return true; 409 return true;
406 return false; 410 return false;
407 } 411 }
408 412
409 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) { 413 void OffscreenCanvasFrameDispatcherImpl::reshape(int width, int height) {
410 m_width = width; 414 m_width = width;
411 m_height = height; 415 m_height = height;
412 } 416 }
413 417
414 } // namespace blink 418 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698