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

Side by Side Diff: cc/resources/gpu_rasterizer.cc

Issue 69343005: Added preliminary support for tile rasterization with Ganesh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (ScopedResource). Created 7 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 | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/gpu_rasterizer.h"
6
7 #include "base/logging.h"
8 #include "cc/output/context_provider.h"
9 #include "cc/resources/resource_format.h"
10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/gpu/GrContext.h"
13 #include "third_party/skia/include/gpu/SkGpuDevice.h"
14 #include "ui/gfx/size_conversions.h"
15
16 namespace cc {
17
18 namespace {
19
20 GrPixelConfig toGrFormat(ResourceFormat format) {
21 switch (format) {
22 case RGBA_8888:
23 return kRGBA_8888_GrPixelConfig;
24 case BGRA_8888:
25 return kBGRA_8888_GrPixelConfig;
26 case RGBA_4444:
27 return kRGBA_4444_GrPixelConfig;
28 default:
29 break; // If you break here, you're gonna have a bad time.
30 }
31 DCHECK(false) << "Unsupported resource format.";
32 return kSkia8888_GrPixelConfig;
33 }
34
35 } // namespace
36
37 GpuRasterizer::RasterTask::RasterTask(
38 Tile* tile, scoped_ptr<ScopedResource> resource)
39 : tile_(tile), resource_(resource.Pass()) {
40 }
41
42 GpuRasterizer::RasterTask::~RasterTask() { }
43
44 GpuRasterizer::Queue::Queue() { }
45
46 GpuRasterizer::Queue::~Queue() { }
47
48 void GpuRasterizer::Queue::Append(
49 Tile* tile, scoped_ptr<ScopedResource> resource) {
50 raster_tasks_.push_back(new RasterTask(tile, resource.Pass()));
51 }
52
53 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
54 ContextProvider* context_provider,
55 ResourceProvider* resource_provider) {
56 return make_scoped_ptr(
57 new GpuRasterizer(context_provider, resource_provider));
58 }
59
60 GpuRasterizer::GpuRasterizer(
61 ContextProvider* context_provider,
62 ResourceProvider* resource_provider)
63 : context_provider_(context_provider),
64 resource_provider_(resource_provider) {
65 }
66
67 GpuRasterizer::~GpuRasterizer() {
68 }
69
70 void GpuRasterizer::SetClient(GpuRasterizerClient* client) {
71 client_ = client;
72 }
73
74 void GpuRasterizer::Rasterize(
75 const Queue& queue,
76 RenderingStatsInstrumentation* rendering_stats_instrumentation) {
77 TRACE_EVENT0("cc", "GpuRasterizer::Rasterize");
78
79 if (queue.raster_tasks_.empty())
80 return;
81
82 blink::WebGraphicsContext3D* context = context_provider_->Context3d();
83 GrContext* gr_context = context_provider_->GrContext();
84 CHECK(client_);
85 CHECK(context);
86 CHECK(gr_context);
87
88 context->makeContextCurrent();
89 gr_context->resetContext();
90 for (RasterTaskVector::const_iterator it = queue.raster_tasks_.begin();
91 it != queue.raster_tasks_.end(); ++it) {
92 RasterTask* task = *it;
93 Tile* tile = task->tile_;
94 DCHECK_NE(task->resource_->id(), 0u);
95 {
96 ResourceProvider::ScopedWriteLockGL lock(
97 resource_provider_, task->resource_->id());
98
99 DCHECK_NE(lock.texture_id(), 0u);
100 GrBackendTextureDesc desc;
101 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
102 desc.fWidth = tile->size().width();
103 desc.fHeight = tile->size().height();
104 desc.fConfig = toGrFormat(lock.format());
105 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
106 desc.fTextureHandle = lock.texture_id();
107 skia::RefPtr<GrTexture> texture =
108 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
109 skia::RefPtr<SkGpuDevice> device =
110 skia::AdoptRef(SkGpuDevice::Create(texture.get()));
111 CHECK(device);
112 skia::RefPtr<SkCanvas> canvas =
113 skia::AdoptRef(new SkCanvas(device.get()));
114
115 if (tile->opaque_rect().IsEmpty())
116 canvas->clear(SK_ColorTRANSPARENT);
117
118 tile->picture_pile()->RasterDirect(
119 canvas.get(), tile->content_rect(), tile->contents_scale(),
120 rendering_stats_instrumentation);
121 }
122
123 client_->OnGpuRasterTaskCompleted(tile, task->resource_.Pass());
124 }
125 gr_context->flush();
126 }
127
128 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698